adding chapter 7 source code

This commit is contained in:
muassif
2021-03-31 09:22:38 +04:00
committed by GitHub
parent 9589675a50
commit f88527eef4
20 changed files with 618 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
# 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")