From 505a48e2687d7178be686248821ff91fb944e79b Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 2 Oct 2025 15:15:08 -0400 Subject: [PATCH] Daemonize the serve_unservicable thread In Python < 3.13, the code backfills a shutdown method for a queue, but this isn't complete; an existing get call is not interrupted by shutdown and this means that when the unservicable queue is empty, it never stops, preventing the system from stopping. By daemonizing the unservicable thread, the server can stop and exit. A better solution would probably involve copying a fair amount of code from Python 3.13's queue implementation. In my opinion that isn't worth the maintenance burden. If desired, perhaps we should only daemonize this thread on Python < 3.13. Signed-off-by: David Manthey --- cheroot/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheroot/server.py b/cheroot/server.py index c836d07c51..e637b53522 100644 --- a/cheroot/server.py +++ b/cheroot/server.py @@ -1929,7 +1929,7 @@ def serve(self): # This thread will handle unservicable connections, as added to # self._unservicable_conns queue. It will run forever, until # self.stop() tells it to shut down. - threading.Thread(target=self._serve_unservicable).start() + threading.Thread(target=self._serve_unservicable, daemon=True).start() while self.ready and not self.interrupt: try: