LoginSignup
5
2

More than 5 years have passed since last update.

Pythonでfire and forget

Last updated at Posted at 2018-10-14

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
5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2