def http_server(request): import httpbin from fulmar.utils import run_in_subprocess httpbin_server = run_in_subprocess(httpbin.app.run, port=55555, passthrough_errors=False) def fin(): httpbin_server.terminate() httpbin_server.join() request.addfinalizer(fin) return httpbin_server
def all(ctx): """ Start scheduler and worker, also run phantomjs if phantomjs is installed. """ g = ctx.obj sub_processes = [] threads = [] try: if not g.get('phantomjs_proxy'): phantomjs_config = g.get('phantomjs', {}) phantomjs_config.setdefault('auto_restart', True) sub_processes.append(utils.run_in_subprocess(ctx.invoke, phantomjs, **phantomjs_config)) time.sleep(2) if sub_processes[-1].is_alive() and not g.get('phantomjs_proxy'): g['phantomjs_proxy'] = '127.0.0.1:%s' % phantomjs_config.get('port', 25555) scheduler_config = g.get('scheduler', {}) threads.append(utils.run_in_thread(ctx.invoke, scheduler, **scheduler_config)) worker_config = g.get('worker', {}) threads.append(utils.run_in_thread(ctx.invoke, worker, **worker_config)) while threads: for t in threads: if not t.isAlive(): threads.remove(t) time.sleep(0.1) for sub_process in sub_processes: sub_process.join() except KeyboardInterrupt: logging.info('Keyboard interrupt. Bye, bye.') finally: # Need to kill subprocesses: phantomjs. for process in sub_processes: process.terminate()