- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlesson01_thread.py
More file actions
Latest commit
17 lines (15 loc) · 463 Bytes
/
Copy pathlesson01_thread.py
File metadata and controls
17 lines (15 loc) · 463 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# SuperFastPython.com
# example of running a function in a new thread
fromthreadingimportThread
# custom function to be executed in a new thread
deftask():
# report a message
print('This is another thread')
# protect the entry point
if__name__=='__main__':
# define a task to run in a new thread
thread=Thread(target=task)
# start the task in a new thread
thread.start()
# wait for the thread to terminate
thread.join()