def ensure_loop(loop: AbstractEventLoop = None) -> AbstractEventLoop: """ Use loop provided or create new if not provided or closed. Return loop passed if its provided,not closed and not running, otherwise returns new event loop. :param loop: optional event loop :return: asyncio event loop """ try: loop = loop or asyncio.new_event_loop() assert not loop.is_closed() assert not loop.is_running() except (RuntimeError, AssertionError): loop = asyncio.new_event_loop() return loop
def sigterm_handler(logger: Logger, event_loop: AbstractEventLoop) -> None: if event_loop.is_running(): logger.info('Received SIGTERM') event_loop.stop()
def sigterm_handler(logger: Logger, event_loop: AbstractEventLoop) -> None: if event_loop.is_running(): logger.info('Received SIGTERM') event_loop.stop()