tem.py 424 B

12345678910111213141516171819
  1. import asyncio
  2. async def say_after(delay:int, what:str):
  3. await asyncio.sleep(delay)
  4. print(what)
  5. async def main():
  6. result1 = asyncio.create_task(say_after(5, 'hello'))
  7. result2 = asyncio.create_task(say_after(5, 'world'))
  8. print("finished")
  9. await result1
  10. await result2
  11. print("done")
  12. print(result1)
  13. print(result2)
  14. if __name__ == "__main__":
  15. asyncio.run(main())