| 12345678910111213141516171819 |
- import asyncio
- async def say_after(delay:int, what:str):
- await asyncio.sleep(delay)
- print(what)
- async def main():
- result1 = asyncio.create_task(say_after(5, 'hello'))
- result2 = asyncio.create_task(say_after(5, 'world'))
- print("finished")
- await result1
- await result2
- print("done")
- print(result1)
- print(result2)
- if __name__ == "__main__":
- asyncio.run(main())
|