How to open daemon thread

# Open daemon thread at a plurality of threads 
from Threading Import the Thread
Import Time
DEF sayHi ():
Print ( 123)
the time.sleep ( . 1)
Print ( 'end123')
DEF bar ():
Print ( 456)
the time.sleep ( . 3)
Print ( 'end456')
IF the __name__ == '__main__':
T1 = the thread ( target = sayHi)
T2 = the thread ( target = bar)
t1.setDaemon ( True) # I daemon thread, the thread must be set before starting
= t1.daemon True # I set up a daemon thread, the thread must be set before the start
t1.start ()
t2.start ()
Print ( 'old-generation eat S%'% 'bird feces is the main thread')
# single thread the open-daemon thread
Threading from Import the Thread
Import Time
DEF Task (name):
the time.sleep ( 2)
Print ( '% S shit' name%)
IF the __name__ == '__main__':
T = the Thread ( target = Task , args = ( 'old Generation ' ,))
t.setDaemon ( True) # I daemon thread, the thread must be set before the start
t.start ()
Print ( ' main ha ha ha ha ')

Guess you like

Origin www.cnblogs.com/yuexijun/p/11542888.html