Skip to content

Commit dbf9d32

Browse files
committed
Various pr feedbacks
Drop extra prefix on tests, fix formating on gh issue file Separate a couple operations into different lines
1 parent b3cc8a2 commit dbf9d32

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

Doc/library/concurrent.futures.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ to a :class:`ProcessPoolExecutor` will result in deadlock.
430430
.. method:: kill_workers()
431431

432432
Attempt to kill all living worker processes immediately by calling
433-
:meth:`Process.terminate <multiprocessing.Process.kill>` on each of them.
433+
:meth:`Process.kill <multiprocessing.Process.kill>` on each of them.
434434
Internally, it will also call :meth:`Executor.shutdown` to ensure that all
435435
other resources associated with the executor are freed.
436436

Lib/concurrent/futures/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ def _terminate_or_kill_workers(self, operation):
874874
submitted).
875875
"""
876876
if operation not in _TERMINATE_OR_KILL_OPERATION:
877-
raise ValueError(f"Unsupported operation: {operation}")
877+
raise ValueError(f"Unsupported operation: {operation!r}")
878878

879879
processes = {}
880880
if self._processes:

Lib/test/test_concurrent_futures/test_process_pool.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,28 +233,28 @@ def mock_start_new_thread(func, *args, **kwargs):
233233
list(executor.map(mul, [(2, 3)] * 10))
234234
executor.shutdown()
235235

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

241241
executor._terminate_or_kill_workers.assert_called_once_with(operation=futures.process._TERMINATE)
242242

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

248248
executor._terminate_or_kill_workers.assert_called_once_with(operation=futures.process._KILL)
249249

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

256256
@parameterize(*TERMINATE_OR_KILL_PARAMS)
257-
def test_process_pool_executor_terminate_kill_workers(self, function_name):
257+
def test_terminate_kill_workers(self, function_name):
258258
manager = self.get_context().Manager()
259259
q = manager.Queue()
260260

@@ -279,7 +279,7 @@ def test_process_pool_executor_terminate_kill_workers(self, function_name):
279279
self.assertRaises(queue.Empty, q.get, timeout=1)
280280

281281
@parameterize(*TERMINATE_OR_KILL_PARAMS)
282-
def test_process_pool_executor_terminate_kill_workers_dead_workers(self, function_name):
282+
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)
285285
self.assertRaises(BrokenProcessPool, future.result)
@@ -288,7 +288,7 @@ def test_process_pool_executor_terminate_kill_workers_dead_workers(self, functio
288288
getattr(executor, function_name)()
289289

290290
@parameterize(*TERMINATE_OR_KILL_PARAMS)
291-
def test_process_pool_executor_terminate_kill_workers_not_started_yet(self, function_name):
291+
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:
294294
with futures.ProcessPoolExecutor(max_workers=1, mp_context=ctx) as executor:
@@ -300,9 +300,10 @@ def test_process_pool_executor_terminate_kill_workers_not_started_yet(self, func
300300
mock_process.return_value.terminate.assert_not_called()
301301

302302
@parameterize(*TERMINATE_OR_KILL_PARAMS)
303-
def test_process_pool_executor_terminate_kill_workers_stops_pool(self, function_name):
303+
def test_terminate_kill_workers_stops_pool(self, function_name):
304304
with futures.ProcessPoolExecutor(max_workers=1) as executor:
305-
executor.submit(time.sleep, 0).result()
305+
task = executor.submit(time.sleep, 0)
306+
self.assertIsNone(task.result())
306307

307308
getattr(executor, function_name)()
308309

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* Add :meth:`concurrent.futures.ProcessPoolExecutor.terminate_workers` and
2-
:meth:`concurrent.futures.ProcessPoolExecutor.terminate_workers` as
3-
ways to terminate or kill all living worker processes in the given pool.
4-
(Contributed by Charles Machalow in :gh:`128043`.)
1+
Add :meth:`concurrent.futures.ProcessPoolExecutor.terminate_workers` and
2+
:meth:`concurrent.futures.ProcessPoolExecutor.terminate_workers` as
3+
ways to terminate or kill all living worker processes in the given pool.
4+
(Contributed by Charles Machalow in :gh:`128043`.)

0 commit comments

Comments
 (0)