Meaning of daemon property on Python Threads

Setting thread.daemon = True will allow the main program to exit. Apps normally wait till all child threads are finished before completing.


th.daemon = True #set this thread as a Daemon Thread

You can think in a Daemon thread as a service this means that it will be running in the background of your computer doing differents task, like indexing files, parsing xml, retrieving news etc, anything that is a long running process.

Your Main thread will finish and your daemon will still be running in the background, that is the reason why your program aka Main thread finish, if you want just put an infinite loop and you will see your thread still running. An example for a daemon thread is the garbage collection.


Is this saying that this program won't ever finish?

Yes, that program won't finish, just try it out.

I ask because I have a situation where in my main thread I'm calling sys.exit(), and the process just hangs and my other threads are running as I can see the log. Does this have anything to do with sys.exit() being called with threads alive?

Yes, even exit won't stop other threads, it simply raises SystemExit in the main thread. So while the main thread will stop (just like it does on any other unhandled Exception), all other non-daemonic threads will continue to work.