Skip to content

Commit 1e16da6

Browse files
committed
PR feedback: swap name of terminate_or_kill to force_shutdown
1 parent dbf9d32 commit 1e16da6

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

Lib/concurrent/futures/process.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ class BrokenProcessPool(_base.BrokenExecutor):
629629
_TERMINATE = "terminate"
630630
_KILL = "kill"
631631

632-
_TERMINATE_OR_KILL_OPERATION = {
632+
_SHUTDOWN_CALLBACK_OPERATION = {
633633
_TERMINATE,
634634
_KILL
635635
}
@@ -864,7 +864,7 @@ def shutdown(self, wait=True, *, cancel_futures=False):
864864

865865
shutdown.__doc__ = _base.Executor.shutdown.__doc__
866866

867-
def _terminate_or_kill_workers(self, operation):
867+
def _force_shutdown(self, operation):
868868
"""Attempts to terminate or kill the executor's workers based off the
869869
given operation. Iterates through all of the current processes and
870870
performs the relevant task if the process is still alive.
@@ -873,7 +873,7 @@ def _terminate_or_kill_workers(self, operation):
873873
and no longer usable (for instance, new tasks should not be
874874
submitted).
875875
"""
876-
if operation not in _TERMINATE_OR_KILL_OPERATION:
876+
if operation not in _SHUTDOWN_CALLBACK_OPERATION:
877877
raise ValueError(f"Unsupported operation: {operation!r}")
878878

879879
processes = {}
@@ -914,7 +914,7 @@ def terminate_workers(self):
914914
and no longer usable (for instance, new tasks should not be
915915
submitted).
916916
"""
917-
return self._terminate_or_kill_workers(operation=_TERMINATE)
917+
return self._force_shutdown(operation=_TERMINATE)
918918

919919
def kill_workers(self):
920920
"""Attempts to kill the executor's workers.
@@ -925,4 +925,4 @@ def kill_workers(self):
925925
and no longer usable (for instance, new tasks should not be
926926
submitted).
927927
"""
928-
return self._terminate_or_kill_workers(operation=_KILL)
928+
return self._force_shutdown(operation=_KILL)

Lib/test/test_concurrent_futures/test_process_pool.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, mgr):
2626
def __del__(self):
2727
self.event.set()
2828

29-
TERMINATE_OR_KILL_PARAMS = [
29+
FORCE_SHUTDOWN_PARAMS = [
3030
dict(function_name='terminate_workers'),
3131
dict(function_name='kill_workers'),
3232
]
@@ -235,25 +235,25 @@ def mock_start_new_thread(func, *args, **kwargs):
235235

236236
def test_terminate_workers(self):
237237
with futures.ProcessPoolExecutor(max_workers=1) as executor:
238-
executor._terminate_or_kill_workers = unittest.mock.Mock()
238+
executor._force_shutdown = unittest.mock.Mock()
239239
executor.terminate_workers()
240240

241-
executor._terminate_or_kill_workers.assert_called_once_with(operation=futures.process._TERMINATE)
241+
executor._force_shutdown.assert_called_once_with(operation=futures.process._TERMINATE)
242242

243243
def test_kill_workers(self):
244244
with futures.ProcessPoolExecutor(max_workers=1) as executor:
245-
executor._terminate_or_kill_workers = unittest.mock.Mock()
245+
executor._force_shutdown = unittest.mock.Mock()
246246
executor.kill_workers()
247247

248-
executor._terminate_or_kill_workers.assert_called_once_with(operation=futures.process._KILL)
248+
executor._force_shutdown.assert_called_once_with(operation=futures.process._KILL)
249249

250-
def test_terminate_or_kill_workers_invalid_op(self):
250+
def test_force_shutdown_workers_invalid_op(self):
251251
with futures.ProcessPoolExecutor(max_workers=1) as executor:
252252
self.assertRaises(ValueError,
253-
executor._terminate_or_kill_workers,
253+
executor._force_shutdown,
254254
operation='invalid operation'),
255255

256-
@parameterize(*TERMINATE_OR_KILL_PARAMS)
256+
@parameterize(*FORCE_SHUTDOWN_PARAMS)
257257
def test_terminate_kill_workers(self, function_name):
258258
manager = self.get_context().Manager()
259259
q = manager.Queue()
@@ -278,7 +278,7 @@ def test_terminate_kill_workers(self, function_name):
278278

279279
self.assertRaises(queue.Empty, q.get, timeout=1)
280280

281-
@parameterize(*TERMINATE_OR_KILL_PARAMS)
281+
@parameterize(*FORCE_SHUTDOWN_PARAMS)
282282
def test_terminate_kill_workers_dead_workers(self, function_name):
283283
with futures.ProcessPoolExecutor(max_workers=1) as executor:
284284
future = executor.submit(os._exit, 1)
@@ -287,7 +287,7 @@ def test_terminate_kill_workers_dead_workers(self, function_name):
287287
# even though the pool is broken, this shouldn't raise
288288
getattr(executor, function_name)()
289289

290-
@parameterize(*TERMINATE_OR_KILL_PARAMS)
290+
@parameterize(*FORCE_SHUTDOWN_PARAMS)
291291
def test_terminate_kill_workers_not_started_yet(self, function_name):
292292
ctx = self.get_context()
293293
with unittest.mock.patch.object(ctx, 'Process') as mock_process:
@@ -299,7 +299,7 @@ def test_terminate_kill_workers_not_started_yet(self, function_name):
299299
mock_process.return_value.kill.assert_not_called()
300300
mock_process.return_value.terminate.assert_not_called()
301301

302-
@parameterize(*TERMINATE_OR_KILL_PARAMS)
302+
@parameterize(*FORCE_SHUTDOWN_PARAMS)
303303
def test_terminate_kill_workers_stops_pool(self, function_name):
304304
with futures.ProcessPoolExecutor(max_workers=1) as executor:
305305
task = executor.submit(time.sleep, 0)

0 commit comments

Comments
 (0)