[Tutor] Thread deamon

Kent Johnson kent37 at tds.net
Mon Aug 22 15:40:42 CEST 2005


Jorge Louis de Castro wrote:
> Are these two equivalent:
> 
> def run_server(socket):
>      ...
> 
> 1)
> thread = Thread(target=run_server, args=(server,))
> #thread.setDaemon(True)
> thread.start()
> 
> 2)
> server.listen(1)
> thread.start_new_thread(run_server,(server,))

They both start threads but the threading module also modifies the behavior of sys.exit() so the program will not exit until all *non* daemon threads exit. So you may get the behaviour you want with 1) as written (without the setDaemon() call). Calling setDaemon(True) *allows* the program to exit before the daemon thread terminates which sounds like the opposite of what you want.

Kent

> 
> So that I can uncomment the setDaemon() method?
> 
> chrs
> j.
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list