Advertisement
DigitalMag

the simplest async hello world

Nov 11th, 2020 (edited)
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.28 KB | None | 0 0
  1. import time
  2. import asyncio
  3.  
  4. loop = asyncio.get_event_loop()
  5.  
  6. async def a_print(v):
  7.     time.sleep(v)
  8.     print(v)
  9.     return v*2
  10.  
  11. async def main():
  12.     loop.create_task(a_print(2))
  13.     print(1)
  14.  
  15. if __name__ == '__main__':
  16.     loop.run_until_complete(main())
  17.  
  18. # 1
  19. # 2
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement