- Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathlesson03_gather.py
More file actions
Latest commit
24 lines (21 loc) · 586 Bytes
/
Copy pathlesson03_gather.py
File metadata and controls
24 lines (21 loc) · 586 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# SuperFastPython.com
# example of gather for many coroutines in a list
importasyncio
# coroutine used for a task
asyncdeftask_coro(value):
# report a message
print(f'>task {value} executing')
# sleep for a moment
awaitasyncio.sleep(1)
# coroutine used for the entry point
asyncdefmain():
# report a message
print('main starting')
# create many coroutines
coros= [task_coro(i) foriinrange(10)]
# run the tasks
awaitasyncio.gather(*coros)
# report a message
print('main done')
# start the asyncio program
asyncio.run(main())