Skip to content

Commit

Permalink
asyncio for myself
Browse files Browse the repository at this point in the history
  • Loading branch information
Patataman authored Mar 28, 2019
1 parent 0ffccd2 commit f40ca54
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions advanced/07-Asyncio2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import asyncio

# definition of a coroutine
async def coroutine(i):
print('coroutine_{} is active on the event loop'.format(i))

print('coroutine_{} yielding control. Going to be blocked for 4 seconds'.format(i))
await asyncio.sleep(4)

print('coroutine_{} resumed. coroutine_1 exiting'.format(i))


# 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(i) for i in range(5)]))

0 comments on commit f40ca54

Please sign in to comment.