- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlesson01_pool.py
More file actions
Latest commit
18 lines (16 loc) · 554 Bytes
/
Copy pathlesson01_pool.py
File metadata and controls
18 lines (16 loc) · 554 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# SuperFastPython.com
# example running a function in the multiprocessing pool
frommultiprocessingimportPool
# custom function to be executed in a child process
deftask():
# report a message
print('This is another process', flush=True)
# protect the entry point
if__name__=='__main__':
# create the multiprocessing pool
withPool() aspool:
# issue the task
async_result=pool.apply_async(task)
# wait for the task to finish
async_result.wait()
# close the multiprocessing pool automatically