-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcode8.py
More file actions
45 lines (33 loc) · 883 Bytes
/
code8.py
File metadata and controls
45 lines (33 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# code8.py
import threading
import logging
import time
logging.basicConfig(level=logging.DEBUG, format='(%(threadName)-10s)'
' %(message)s')
class DaemonThread(threading.Thread):
def __init__(self, t):
super().__init__()
self.t = t
self.daemon = True
def run(self):
logging.debug('Starting')
time.sleep(self.t)
logging.debug('Exiting')
class NonDaemonThread(threading.Thread):
def __init__(self, t):
super().__init__()
self.t = t
self.daemon = True
def run(self):
logging.debug('Starting')
time.sleep(self.t)
logging.debug('Exiting')
# Creating threads
d = DaemonThread(2)
t = NonDaemonThread(1)
# Executing threads
d.start()
t.start()
# Waiting for the threads finish
d.join()
t.join()