- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlesson02_num_processes.py
More file actions
Latest commit
19 lines (17 loc) · 556 Bytes
/
Copy pathlesson02_num_processes.py
File metadata and controls
19 lines (17 loc) · 556 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# SuperFastPython.com
# example of setting a large number number of workers
fromtimeimportsleep
fromconcurrent.futuresimportProcessPoolExecutor
# custom task function executed in the process pool
deftask(number):
# block for a moment
sleep(1)
# report a message
ifnumber%10==0:
print(f'>task {number} done', flush=True)
# protect the entry point
if__name__=='__main__':
# create a process pool
withProcessPoolExecutor(50) asexe:
# issue many tasks to the pool
_=exe.map(task, range(50))