def syncer(*args, **kwargs) -> Any: loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) result = loop.run_until_complete(maybe_coroutine( func, *args, **kwargs)) shutdown_loop(loop) return result
def run(loop: asyncio.AbstractEventLoop) -> None: try: loop.add_signal_handler(signal.SIGINT, loop.stop) loop.add_signal_handler(signal.SIGTERM, loop.stop) except (NotImplementedError, RuntimeError): pass asyncio.set_event_loop(loop) try: loop.run_forever() except KeyboardInterrupt: log.info("Received the signal to terminate the event loop.") finally: log.info("Cleaning up tasks.") shutdown_loop(loop)