- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlesson06_apply.py
More file actions
Latest commit
17 lines (15 loc) · 502 Bytes
/
Copy pathlesson06_apply.py
File metadata and controls
17 lines (15 loc) · 502 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# SuperFastPython.com
# example of executing an async one-off task
frommultiprocessing.poolimportThreadPool
# custom function to be executed in a worker thread
deftask():
# report a message
print('This is a worker thread')
# protect the entry point
if__name__=='__main__':
# create the thread pool
withThreadPool() aspool:
# issue a task asynchronously
async_result=pool.apply_async(task)
# wait for the task to complete
async_result.wait()