- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlesson06_map.py
More file actions
Latest commit
19 lines (17 loc) · 561 Bytes
/
Copy pathlesson06_map.py
File metadata and controls
19 lines (17 loc) · 561 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# SuperFastPython.com
# example executing multiple tasks with different args
frommultiprocessing.poolimportThreadPool
# custom function to be executed in a worker thread
deftask(arg):
# report a message
print(f'Worker task got {arg}')
# return a value
returnarg*2
# protect the entry point
if__name__=='__main__':
# create the thread pool
withThreadPool() aspool:
# issue multiple tasks and handle return values
forresultinpool.map(task, range(10)):
# report result
print(result)