summaryrefslogtreecommitdiffstats
path: root/Lib/socketserver.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-05-24 01:14:44 (GMT)
committerGitHub <noreply@github.com>2018-05-24 01:14:44 (GMT)
commit453bd0bc65b7ea6a18c43da69143ab10d54c0a35 (patch)
tree6c3c61b643d1b80dfa63508e3b8de265ee4c40ab /Lib/socketserver.py
parentb97de3dd86046ac46567146d86a69d4f78ea09db (diff)
downloadcpython-453bd0bc65b7ea6a18c43da69143ab10d54c0a35.zip
cpython-453bd0bc65b7ea6a18c43da69143ab10d54c0a35.tar.gz
cpython-453bd0bc65b7ea6a18c43da69143ab10d54c0a35.tar.bz2
bpo-33540: Add block_on_close attr to socketserver (GH-6911)
Add a new block_on_close class attribute to ForkingMixIn and ThreadingMixIn classes of socketserver to opt-in for pre-3.7 behaviour.
Diffstat (limited to 'Lib/socketserver.py')
-rw-r--r--Lib/socketserver.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/Lib/socketserver.py b/Lib/socketserver.py
index 1ae7bef..71bb9a4 100644
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -543,6 +543,8 @@ if hasattr(os, "fork"):
timeout = 300
active_children = None
max_children = 40
+ # If true, server_close() waits until all child processes complete.
+ block_on_close = True
def collect_children(self, *, blocking=False):
"""Internal routine to wait for children that have exited."""
@@ -620,7 +622,7 @@ if hasattr(os, "fork"):
def server_close(self):
super().server_close()
- self.collect_children(blocking=True)
+ self.collect_children(blocking=self.block_on_close)
class ThreadingMixIn:
@@ -629,6 +631,8 @@ class ThreadingMixIn:
# Decides how threads will act upon termination of the
# main process
daemon_threads = False
+ # If true, server_close() waits until all non-daemonic threads terminate.
+ block_on_close = True
# For non-daemonic threads, list of threading.Threading objects
# used by server_close() to wait for all threads completion.
_threads = None
@@ -659,11 +663,12 @@ class ThreadingMixIn:
def server_close(self):
super().server_close()
- threads = self._threads
- self._threads = None
- if threads:
- for thread in threads:
- thread.join()
+ if self.block_on_close:
+ threads = self._threads
+ self._threads = None
+ if threads:
+ for thread in threads:
+ thread.join()
if hasattr(os, "fork"):