def _before_train(self): for p in self.predictors: self.predictors[p].start() def f(): msg = loads(self.sim2coord_socket.recv(copy=False).bytes) sim_name = msg[0] agent_name = msg[1] def cb(outputs): try: output = outputs.result() except CancelledError: logger.info("{} cancelled.".format(sim_name)) return print('coordinator sending', sim_name.encode('utf-8'), output[0].shape) self.coord2sim_socket.send_multipart( [sim_name.encode('utf-8'), dumps(output[0])]) self.predictors[agent_name].put_task(msg[2:], cb) self.recv_thread = ShareSessionThread(LoopThread(f, pausable=False)) # self.recv_thread.daemon = True self.recv_thread.name = 'coordinator recv' self.recv_thread.start() logger.info('Coordinator started')
def _create_simulator_thread(self, idx): # spawn a separate thread to run policy def populate_job_func(): exp = self._populate_job_queue.get() self._runners[idx].step(exp) th = ShareSessionThread(LoopThread(populate_job_func, pausable=False)) th.name = "SimulatorThread-{}".format(idx) return th
def get_simulator_thread(self): # spawn a separate thread to run policy def populate_job_func(): self._populate_job_queue.get() for _ in range(self.update_frequency): self._populate_exp() th = ShareSessionThread(LoopThread(populate_job_func, pausable=False)) th.name = "SimulatorThread" return th
def get_simulator_thread(self): # spawn a separate thread to run policy def populate_job_func(): self._populate_job_queue.get() ############################################################################### # HITL UPDATE # as self.update_frequency = 0 during pretraining, no workers will be initialized. ############################################################################### #logger.info("update_frequency: {}".format(self.update_frequency)) for _ in range(int(self.update_frequency)): self._populate_exp() th = ShareSessionThread(LoopThread(populate_job_func, pausable=False)) th.name = "SimulatorThread" return th
def get_simulator_thread(self): # spawn a separate thread to run policy def populate_job_func(): self._populate_job_queue.get() i = 0 # synchronous training while i < self.update_frequency: if self._populate_exp(): i += 1 time.sleep(0.1) # for _ in range(self.update_frequency): # self._populate_exp() th = ShareSessionThread(LoopThread(populate_job_func, pausable=False)) th.name = "SimulatorThread" return th