summaryrefslogtreecommitdiff
path: root/Lib/multiprocessing/managers.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-04-19 16:27:00 +0200
committerGitHub <noreply@github.com>2022-04-19 16:27:00 +0200
commit061a8bf77c80036bed3ef4973fe0c99705c83fc6 (patch)
tree19c2418fd5877d4b3cc211e7f40eff5ad5397a08 /Lib/multiprocessing/managers.py
parent74070085da5322ac83c954f101f2caa150655be2 (diff)
downloadcpython-git-061a8bf77c80036bed3ef4973fe0c99705c83fc6.tar.gz
gh-91231: Add shutdown_timeout to multiprocessing BaseManager (#32112)
Add an optional keyword 'shutdown_timeout' parameter to the multiprocessing.BaseManager constructor. Kill the process if terminate() takes longer than the timeout. Multiprocessing tests pass test.support.SHORT_TIMEOUT to BaseManager.shutdown_timeout.
Diffstat (limited to 'Lib/multiprocessing/managers.py')
-rw-r--r--Lib/multiprocessing/managers.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py
index d97381926d..3f6479b7e3 100644
--- a/Lib/multiprocessing/managers.py
+++ b/Lib/multiprocessing/managers.py
@@ -497,7 +497,7 @@ class BaseManager(object):
_Server = Server
def __init__(self, address=None, authkey=None, serializer='pickle',
- ctx=None):
+ ctx=None, *, shutdown_timeout=1.0):
if authkey is None:
authkey = process.current_process().authkey
self._address = address # XXX not final address if eg ('', 0)
@@ -507,6 +507,7 @@ class BaseManager(object):
self._serializer = serializer
self._Listener, self._Client = listener_client[serializer]
self._ctx = ctx or get_context()
+ self._shutdown_timeout = shutdown_timeout
def get_server(self):
'''
@@ -570,8 +571,8 @@ class BaseManager(object):
self._state.value = State.STARTED
self.shutdown = util.Finalize(
self, type(self)._finalize_manager,
- args=(self._process, self._address, self._authkey,
- self._state, self._Client),
+ args=(self._process, self._address, self._authkey, self._state,
+ self._Client, self._shutdown_timeout),
exitpriority=0
)
@@ -656,7 +657,8 @@ class BaseManager(object):
self.shutdown()
@staticmethod
- def _finalize_manager(process, address, authkey, state, _Client):
+ def _finalize_manager(process, address, authkey, state, _Client,
+ shutdown_timeout):
'''
Shutdown the manager process; will be registered as a finalizer
'''
@@ -671,15 +673,17 @@ class BaseManager(object):
except Exception:
pass
- process.join(timeout=1.0)
+ process.join(timeout=shutdown_timeout)
if process.is_alive():
util.info('manager still alive')
if hasattr(process, 'terminate'):
util.info('trying to `terminate()` manager process')
process.terminate()
- process.join(timeout=0.1)
+ process.join(timeout=shutdown_timeout)
if process.is_alive():
util.info('manager still alive after terminate')
+ process.kill()
+ process.join()
state.value = State.SHUTDOWN
try: