Skip to content

Commit 1b4660b

Browse files
Create threading_daemon.py
1 parent 11ecd42 commit 1b4660b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

scripts/threading_daemon.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
import threading
3+
import time
4+
import logging
5+
6+
7+
def daemon():
8+
logging.debug('Starting')
9+
time.sleep(0.2)
10+
logging.debug('Exiting')
11+
12+
13+
def non_daemon():
14+
logging.debug('Starting')
15+
logging.debug('Exiting')
16+
17+
18+
logging.basicConfig(
19+
level=logging.DEBUG,
20+
format='(%(threadName)-10s) %(message)s',
21+
)
22+
23+
d = threading.Thread(name='daemon', target=daemon, daemon=True)
24+
25+
t = threading.Thread(name='non-daemon', target=non_daemon)
26+
27+
d.start()
28+
t.start()

0 commit comments

Comments
 (0)