- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathlesson06_map.py
More file actions
Latest commit
19 lines (17 loc) · 566 Bytes
/
Copy pathlesson06_map.py
File metadata and controls
19 lines (17 loc) · 566 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
frommultiprocessingimportPool
# custom function to be executed in a child process
deftask(arg):
# report a message
print(f'Worker task got {arg}', flush=True)
# return a value
returnarg*2
# protect the entry point
if__name__=='__main__':
# create the multiprocessing pool
withPool() aspool:
# issue multiple tasks and process return values
forresultinpool.map(task, range(10)):
# report result
print(result)