29 lines
678 B
Python
29 lines
678 B
Python
# thread2.py to create daemon and non-daemon threads
|
|
|
|
from threading import current_thread, Thread as Thread
|
|
from time import sleep
|
|
|
|
def daeom_func():
|
|
#print(threading.current_thread().isDaemon())
|
|
sleep(3)
|
|
print("{}: Hello from daemon".format
|
|
(current_thread().name))
|
|
|
|
|
|
def nondaeom_func():
|
|
#print(threading.current_thread().isDaemon())
|
|
sleep(1)
|
|
print("{}: Hello from non-daemon".format(
|
|
current_thread().name))
|
|
|
|
|
|
# creating threads
|
|
t1 = Thread(target=daeom_func, name="Daemon Thread",daemon=True)
|
|
t2 = Thread(target=nondaeom_func, name="Non-Daemon Thread")
|
|
|
|
# start the threads
|
|
t1.start()
|
|
t2.start()
|
|
|
|
|
|
print("Exiting the main program") |