Guest User

Untitled

a guest
Jun 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import asyncio
  2.  
  3. # definition of a coroutine
  4. async def coroutine_1():
  5. print('coroutine_1 is active on the event loop')
  6. # yield control to the event loop
  7. print('coroutine_1 pausing')
  8. await asyncio.sleep(2)
  9. print('coroutine_1 resumed. coroutine_1 exiting')
  10.  
  11. # definition of a coroutine
  12. async def coroutine_2():
  13. print('coroutine_2 is active on the event loop')
  14. # yield control to the event loop
  15. print('coroutine_2 pausing')
  16. await asyncio.sleep(1)
  17. print('coroutine_2 resumed. coroutine_2 exiting')
  18.  
  19. # this is the event loop
  20. loop = asyncio.get_event_loop()
  21.  
  22. # schedule both the coroutines to run on the event loop
  23. loop.run_until_complete(asyncio.gather(coroutine_1(), coroutine_2()))
Add Comment
Please, Sign In to add comment