Advertisement
DigitalMag

Test: when a_print is executed: before print(9) or until

Nov 11th, 2020
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 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.     asyncio.sleep(v)
  9.     print(v)
  10.     return v**2
  11.  
  12. async def main(sync, v):
  13.     # loop.create_task(a_print(v+1))
  14.     task = loop.create_task(a_print(v+1))
  15.     start()
  16.     print(r)
  17.  
  18.     r = await task
  19.     # time.sleep(v)
  20.     asyncio.sleep(v)
  21.     print(v)
  22.  
  23. def start():
  24.     print(9)
  25.  
  26. if __name__ == '__main__':
  27.     loop.run_until_complete(main(start, 1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement