forked from x4nth055/pythoncode-tutorials
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaemon_thread.py
More file actions
Latest commit
18 lines (16 loc) · 481 Bytes
/
Copy pathdaemon_thread.py
File metadata and controls
18 lines (16 loc) · 481 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
importthreading
importtime
deffunc_1():
whileTrue:
print(f"[{threading.current_thread().name}] Printing this message every 2 seconds")
time.sleep(2)
# initiate the thread with daemon set to True
daemon_thread=threading.Thread(target=func_1, name="daemon-thread", daemon=True)
# or
# daemon_thread.daemon = True
# or
# daemon_thread.setDaemon(True)
daemon_thread.start()
# sleep for 10 seconds and end the main thread
time.sleep(4)
# the main thread ends