def setup(self, config): # Semaphore for notifying the reporter to continue with the computation # and to generate the next result. self._continue_semaphore = threading.Semaphore(0) # Event for notifying the reporter to exit gracefully, terminating # the thread. self._end_event = threading.Event() # Queue for passing results between threads self._results_queue = queue.Queue(1) # Queue for passing errors back from the thread runner. The error queue # has a max size of one to prevent stacking error and force error # reporting to block until finished. self._error_queue = queue.Queue(1) self._status_reporter = StatusReporter(self._results_queue, self._continue_semaphore, self._end_event, trial_name=self.trial_name, trial_id=self.trial_id, logdir=self.logdir) self._last_result = {} session.init(self._status_reporter) self._runner = None self._restore_tmpdir = None self.temp_checkpoint_dir = None
def _setup(self, config): # Semaphore for notifying the reporter to continue with the computation # and to generate the next result. self._continue_semaphore = threading.Semaphore(0) # Queue for passing results between threads self._results_queue = queue.Queue(1) # Queue for passing errors back from the thread runner. The error queue # has a max size of one to prevent stacking error and force error # reporting to block until finished. self._error_queue = queue.Queue(1) self._status_reporter = StatusReporter(self._results_queue, self._continue_semaphore, trial_name=self.trial_name, trial_id=self.trial_id, logdir=self.logdir) self._last_result = {} config = config.copy() session.init(self._status_reporter) def entrypoint(): return self._trainable_func(config, self._status_reporter) # the runner thread is not started until the first call to _train self._runner = _RunnerThread(entrypoint, self._error_queue)
def testSessionInitShutdown(self): self.assertTrue(session._session is None) # Checks that the singleton _session is created/destroyed # by session.init() and session.shutdown() for _ in range(2): # do it twice to see that we can reopen the session session.init(reporter=None) self.assertTrue(session._session is not None) session.shutdown() self.assertTrue(session._session is None)