Skip to content

Commit a1aff76

Browse files
committed
Use _NoThreads as the default value. Fixes AttributeError when server is closed without serving any requests.
1 parent b107b91 commit a1aff76

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Lib/socketserver.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ class ThreadingMixIn:
688688
block_on_close = True
689689
# Threads object
690690
# used by server_close() to wait for all threads completion.
691-
_threads = None
691+
_threads = _NoThreads()
692692

693693
def process_request_thread(self, request, client_address):
694694
"""Same as in BaseServer but as a thread.
@@ -708,10 +708,8 @@ def process_request_thread(self, request, client_address):
708708

709709
def process_request(self, request, client_address):
710710
"""Start a new thread to process the request."""
711-
vars(self).setdefault(
712-
'_threads',
713-
_Threads() if self.block_on_close else _NoThreads(),
714-
)
711+
if self.block_on_close:
712+
vars(self).setdefault('_threads', _Threads())
715713
t = threading.Thread(target = self.process_request_thread,
716714
args = (request, client_address))
717715
t.daemon = self.daemon_threads

0 commit comments

Comments
 (0)