I use the socketserver.ThreadingMixIn to create a TCPServer. I set the server thread as daemon (t.daemon=True). But I want the client threads to run as non-daemon. According to the documentation, the "daemon_threads" class attribute should do the trick. But it fails: if server is daemon, the clients are daemon too, even if daemon_threads=False. Demo attached.
""" """Start a new thread to process the request.""" t = threading.Thread(target = self.process_request_thread, args = (request, client_address)) if self.daemon_threads: t.daemon = True """ If daemon_threads is false, t.daemon is not set, and the daemonic property is inherited from the creating thread, i.e. the server thread. Patch attached (I don't think a test is necessary for such a trivial change).
I would prefer to preserve the inheritance by default, and to change the daemonic attribute only if it is explicitly set to True or False. This way it will be backward compatible. Patch attached.
> I would prefer to preserve the inheritance by default, and to change the daemonic attribute only if it is explicitly set to True or False. > This way it will be backward compatible. It may be backward compatible, but IMHO, the current behavior is broken: while it can certainly make sense to set the server thread daemonic, you most certainly don't want to have client threads daemonic implicitely (since you usually don't want to terminate the client's connections abruptly when the main thread exits). But I must admit I don't have a strong opinion, so both solutions are OK to me. The only thing that bothers me is this: """ +.. versionchanged:: 3.3 + previously, the *daemon_threads = False* flag was ignored. """ You usually document new features or behavior changes: this really looks like a bug fix (and is one actually). Something like "the semantics of *daemon_threads* changed slighty" might be better (but I'm no native speaker).