Esempio n. 1
0
 async def main():
     loop = asyncio.get_event_loop()
     if spawn_method == "create_task":
         loop.create_task(shutdown_waits_for(corofn()))
     elif spawn_method == "ensure_future":
         asyncio.ensure_future(shutdown_waits_for(corofn()))
     elif spawn_method == "await":
         await shutdown_waits_for(corofn())
     elif spawn_method == "bare":
         shutdown_waits_for(corofn())
Esempio n. 2
0
 async def main():
     shutdown_waits_for(corofn())  # <-- Look Ma! No awaits!
Esempio n. 3
0
 async def main():
     loop = asyncio.get_event_loop()
     loop.create_task(shutdown_waits_for(corofn()))
Esempio n. 4
0
 async def main():
     # Note that we don't need a loop variable anywhere!
     asyncio.ensure_future(shutdown_waits_for(corofn()))
Esempio n. 5
0
             asyncio.current_task()]

    [task.cancel() for task in tasks]

    logging.info(f'Cancelling {len(tasks)} outstanding tasks')
    await asyncio.gather(*tasks)
    loop.stop()
    logging.info('Shutdown complete.')


if __name__ == '__main__':
    loop = asyncio.get_event_loop()

    # May want to catch other signals too
    signals = (signal.SIGHUP, signal.SIGTERM, signal.SIGINT)
    for s in signals:
        loop.add_signal_handler(
            s, lambda s=s: asyncio.create_task(shutdown(s, loop)))

    shielded_coro = cant_stop_me()
    shielded_coro = aiorun.shutdown_waits_for(handle_exception(shielded_coro, loop))

    aiorun.run(shielded_coro)

    # try:
    #     loop.create_task(shielded_coro)
    #     loop.run_forever()
    # finally:
    #     logging.info('Cleaning up')
    #     loop.stop()