- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathlesson02_custom_function.py
More file actions
Latest commit
21 lines (19 loc) · 607 Bytes
/
Copy pathlesson02_custom_function.py
File metadata and controls
21 lines (19 loc) · 607 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# SuperFastPython.com
# example of running a function in a new child process
fromtimeimportsleep
frommultiprocessingimportProcess
# custom function to be executed in a child process
deftask():
# block for a moment
sleep(1)
# report a message
print('This is from another process', flush=True)
# protect the entry point
if__name__=='__main__':
# create a new process instance
process=Process(target=task)
# start executing the function in the process
process.start()
# wait for the process to finish
print('Waiting for the process...')
process.join()