def run(ctx): """ Continuously run the worker """ if ctx.obj['pidfile']: with open(ctx.obj['pidfile'], 'w') as fd: fd.write(str(os.getpid())) try: try: worker = WorkerInfrastructure(ctx.config) # Set up signalling. do it here as of no relevance to GUI kill_workers = worker_job(worker, lambda: worker.stop(pause=True)) # These first two UNIX & Windows signal.signal(signal.SIGTERM, kill_workers) signal.signal(signal.SIGINT, kill_workers) try: # These signals are UNIX-only territory, will ValueError here on Windows signal.signal(signal.SIGHUP, kill_workers) # TODO: reload config on SIGUSR1 # signal.signal(signal.SIGUSR1, lambda x, y: worker.do_next_tick(worker.reread_config)) except AttributeError: log.debug( "Cannot set all signals -- not available on this platform") worker.run() finally: if ctx.obj['pidfile']: os.unlink(ctx.obj['pidfile']) except errors.NoWorkersAvailable: sys.exit(70) # 70= "Software error" in /usr/include/sysexts.h
def create_worker(self, worker_name, config, view): # Todo: Add some threading here so that the GUI doesn't freeze if self.worker_manager and self.worker_manager.is_alive(): self.worker_manager.add_worker(worker_name, config) else: self.worker_manager = WorkerInfrastructure(config, self.bitshares_instance, view) self.worker_manager.daemon = True self.worker_manager.start()
def test_worker_infrastructure(bitshares, config): """Test whether dexbot core is able to work.""" worker_infrastructure = WorkerInfrastructure(config=config, bitshares_instance=bitshares) def wait_then_stop(): time.sleep(1) worker_infrastructure.do_next_tick(worker_infrastructure.stop(pause=True)) stopper = threading.Thread(target=wait_then_stop) stopper.start() worker_infrastructure.run() stopper.join()
def test_dexbot(self): bitshares_instance = BitShares(node=TEST_CONFIG['node'], keys=KEYS) worker_infrastructure = WorkerInfrastructure( config=TEST_CONFIG, bitshares_instance=bitshares_instance) import pdb pdb.set_trace() def wait_then_stop(): time.sleep(20) worker_infrastructure.do_next_tick(worker_infrastructure.stop) stopper = threading.Thread(target=wait_then_stop) stopper.start() worker_infrastructure.run() stopper.join()
def pause_worker(self, worker_name, config=None): if self.worker_manager and self.worker_manager.is_alive(): self.worker_manager.stop(worker_name, pause=True) else: self.worker_manager = WorkerInfrastructure(config, self.bitshares_instance)