Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- # definition of a coroutine
- async def coroutine_1():
- print('coroutine_1 is active on the event loop')
- # yield control to the event loop
- print('coroutine_1 pausing')
- await asyncio.sleep(2)
- print('coroutine_1 resumed. coroutine_1 exiting')
- # definition of a coroutine
- async def coroutine_2():
- print('coroutine_2 is active on the event loop')
- # yield control to the event loop
- print('coroutine_2 pausing')
- await asyncio.sleep(1)
- print('coroutine_2 resumed. coroutine_2 exiting')
- # this is the event loop
- loop = asyncio.get_event_loop()
- # schedule both the coroutines to run on the event loop
- loop.run_until_complete(asyncio.gather(coroutine_1(), coroutine_2()))
Add Comment
Please, Sign In to add comment