- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlesson03_map.py
More file actions
Latest commit
18 lines (16 loc) · 538 Bytes
/
Copy pathlesson03_map.py
File metadata and controls
18 lines (16 loc) · 538 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# SuperFastPython.com
# example of executing multiple tasks and waiting
frommultiprocessingimportPool
# custom function to be executed in a child process
deftask(arg):
# report a message
print(f'From another process {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)):
print(result)