def _process(args): global _STOP if args.processes > 1: signal.signal(signal.SIGINT, _shutdown) signal.signal(signal.SIGTERM, _shutdown) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) else: loop = asyncio.get_event_loop() if args.debug: log('**** RUNNING IN DEBUG MODE == SLOW ****') loop.set_debug(True) results = {'OK': 0, 'FAILED': 0} stream = asyncio.Queue(loop=loop) co_tasks = [] if args.statsd: statsd = get_statsd_client(args.statsd_server, args.statsd_port) stastd_task = asyncio.ensure_future(statsd.run()) else: statsd = stastd_task = None consumer = asyncio.ensure_future( consume(stream, args.workers, args.console, args.verbose)) co_tasks.append(consumer) _TASKS.extend(co_tasks) co_tasks = asyncio.gather(*co_tasks, loop=loop, return_exceptions=True) workers = _runner(loop, args, results, stream, statsd) run_task = asyncio.gather(*workers, loop=loop, return_exceptions=True) _TASKS.extend(workers) _STATSD.append((statsd, stastd_task)) try: loop.run_until_complete(run_task) except asyncio.CancelledError: _STOP = True co_tasks.cancel() loop.run_until_complete(co_tasks) run_task.cancel() loop.run_until_complete(run_task) finally: _stop_statsd() for task in _TASKS: del task loop.close() return results
def _process(args): global _STOP, _STARTED_AT, _TOLERANCE _STARTED_AT = _TOLERANCE = _now() console = args.shared_console if args.processes > 1: signal.signal(signal.SIGINT, _shutdown) signal.signal(signal.SIGTERM, _shutdown) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) else: loop = asyncio.get_event_loop() if args.debug: console.print('**** RUNNING IN DEBUG MODE == SLOW ****') loop.set_debug(True) display = asyncio.ensure_future(console.display()) co_tasks = [display] if args.original_pid == os.getpid(): co_tasks.append(asyncio.ensure_future(_results(console, args.console_update))) if args.statsd: statsd = get_statsd_client(args.statsd_address, loop=loop) else: statsd = None _TASKS.extend(co_tasks) co_tasks = asyncio.gather(*co_tasks, loop=loop, return_exceptions=True) workers = _runner(loop, args, statsd) run_task = asyncio.gather(*workers, loop=loop, return_exceptions=True) _TASKS.extend(workers) try: loop.run_until_complete(run_task) _STOP = True except asyncio.CancelledError: _STOP = True co_tasks.cancel() loop.run_until_complete(co_tasks) run_task.cancel() loop.run_until_complete(run_task) finally: console.stop() loop.run_until_complete(co_tasks) if statsd is not None: statsd.close() for task in _TASKS: del task loop.close()
def _set_statsd(self): if self.args.statsd: self.statsd = get_statsd_client(self.args.statsd_address) else: self.statsd = None
def _set_statsd(self): if self.args.statsd: self.statsd = get_statsd_client(self.args.statsd_address, loop=self.loop) else: self.statsd = None