- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlesson02_run_function.py
More file actions
Latest commit
21 lines (19 loc) · 573 Bytes
/
Copy pathlesson02_run_function.py
File metadata and controls
21 lines (19 loc) · 573 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 thread
fromtimeimportsleep
fromthreadingimportThread
# custom function to be executed in a new thread
deftask():
# block for a moment
sleep(1)
# report a message
print('This is from another thread')
# protect the entry point
if__name__=='__main__':
# create a new thread instance
thread=Thread(target=task)
# start executing the function in the new thread
thread.start()
# wait for the thread to finish
print('Waiting for the thread...')
thread.join()