def run ( * tasks : Awaitable , loop : asyncio . AbstractEventLoop = asyncio . get_event_loop ( ) ) : futures = [ asyncio . ensure_future ( task , loop = loop ) for task in tasks ] return loop . run_until_complete ( asyncio . gather ( * futures ) )
python asyncio dynamically add tasks to event loop
Helper to run tasks in the event loop
def run(*tasks: Awaitable, loop: asyncio.AbstractEventLoop=asyncio.get_event_loop()):
    """Helper to run tasks in the event loop

    :param tasks: Tasks to run in the event loop.
    :param loop: The event loop.
    """
    futures = [asyncio.ensure_future(task, loop=loop) for task in tasks]
    return loop.run_until_complete(asyncio.gather(*futures))