Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7d370d2

Browse filesBrowse files
committed
add daemon thread tutorial
1 parent ce92525 commit 7d370d2
Copy full SHA for 7d370d2

File tree

Expand file treeCollapse file tree

4 files changed

+35
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+35
-0
lines changed
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
121121
- [Logging in Python](https://www.thepythoncode.com/article/logging-in-python). ([code](python-standard-library/logging))
122122
- [How to Make a Chat Application in Python](https://www.thepythoncode.com/article/make-a-chat-room-application-in-python). ([code](python-standard-library/chat-application))
123123
- [How to Delete Emails in Python](https://www.thepythoncode.com/article/deleting-emails-in-python). ([code](python-standard-library/deleting-emails))
124+
- [Daemon Threads in Python](https://www.thepythoncode.com/article/daemon-threads-in-python). ([code](python-standard-library/daemon-thread))
124125

125126
- ### [Using APIs](https://www.thepythoncode.com/topic/using-apis-in-python)
126127
- [How to Automate your VPS or Dedicated Server Management in Python](https://www.thepythoncode.com/article/automate-veesp-server-management-in-python). ([code](general/automating-server-management))
Collapse file
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [Daemon Threads in Python](https://www.thepythoncode.com/article/daemon-threads-in-python)
Collapse file
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import threading
2+
import time
3+
4+
def func_1():
5+
while True:
6+
print(f"[{threading.current_thread().name}] Printing this message every 2 seconds")
7+
time.sleep(2)
8+
9+
# initiate the thread with daemon set to True
10+
daemon_thread = threading.Thread(target=func_1, name="daemon-thread", daemon=True)
11+
# or
12+
# daemon_thread.daemon = True
13+
# or
14+
# daemon_thread.setDaemon(True)
15+
daemon_thread.start()
16+
# sleep for 10 seconds and end the main thread
17+
time.sleep(4)
18+
# the main thread ends
Collapse file
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import threading
2+
import time
3+
4+
def func():
5+
while True:
6+
print(f"[{threading.current_thread().name}] Printing this message every 2 seconds")
7+
time.sleep(2)
8+
9+
# initiate the thread to call the above function
10+
normal_thread = threading.Thread(target=func, name="normal_thread")
11+
# start the thread
12+
normal_thread.start()
13+
# sleep for 4 seconds and end the main thread
14+
time.sleep(4)
15+
# the main thread ends

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.