python - Unable to use thread.setDaemon(True) to terminate child thread on termination of main program -


file 1 sravi.py

def sam():     while true:         print "hi" 

main program/file trial.py

from threading import thread import sravi x=thread(target=sravi.sam) #x.setdaemon(true) #x.daemon=true x.start() 

i want print "hi" stop once main thread ends continues print hi. have tried x.setdaemon(true) , x.daemon=true not working. understand such questions had been asked before unable figure out solution

-------o/p-------

>>> >>>hi hi hi hi hi hi hi 

it continues print hi

when x.setdaemon(true), thread x terminated when main thread ends.
prove use following code :

from threading import thread def sam():     while true:     print "hi"   x=thread(target=sam) x.setdaemon(true) x.start() time.sleep(2) 

you see after 2 seconds sam function stop printing "hi".


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -