Edited at

Pythonでfire and forget

More than 1 year has passed since last update.


Pythonでfire and forgetする

import time

import asyncio

async def wait(sec: int):
time.sleep(sec)
print('I woke up')

async def main():
asyncio.ensure_future(wait(3))
print('Hey, wake up!')

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


実行結果

Hey, wake up!

I woke up