> What exactly is the advantage of a daemon thread over a normal > one in that case - other than that the application will end while > daemons are still running? In fact that might be the advantage. > But in that case daemons would only be useful for endless > loop type threads?
for example, they can be worker threads, those that take some service request, perform some work, produces results, then goes back to wait for more work -- your endless loop scenario. if the main thread is taking user input and pawning off service requests to worker threads, then exits, meaning no more possible work for the worker threads, they should then be killed off along with the main thread. here's a snippet from the 1st link i sent: "Daemon threads are designed as low-level background threads that perform useful work. However, it is not essential that they be allowed to complete before an application terminates. One example of a daemon thread is the garbage collector thread." if the main (and other non-daemon) threads exit, there is no more code allocating memory (thus no longer a need to GC memory... IOW, there's no more work to be done), so there really isn't a reason for them (daemon threads) to stay up and running. the bottom line is that they can do work when work is available, but other than that, are pretty useless without some non-daemon threads providing that work for them; thus it's relatively harmless to kill them off. FWIW, when i first learned about daemon threads, i was also confused at the naming and their relationship (if any) with daemon/server processes even though they do similar things. i guess that's what makes it easy to reboot your *nix servers... you shutdown and/or reboot without explicitly killing each server right? it sure would take a long time... can you imagine how many "/etc/init.d/XXX stop" calls you'd have to make in your shell? :-) HTH, -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor