Skip to content

Commit 7cfa42e

Browse files
committed
Harden a test a bit to ensure the correct type of kill/terminate was used
1 parent f9a7714 commit 7cfa42e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Lib/test/test_concurrent_futures/test_process_pool.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import multiprocessing
22
import os
33
import queue
4+
import signal
45
import sys
56
import threading
67
import time
@@ -238,7 +239,15 @@ def test_process_pool_executor_terminate_kill_workers(self):
238239
# We should get started, but not finished since we'll terminate the workers just after
239240
self.assertEqual(q.get(timeout=1), 'started')
240241

242+
worker_process = list(executor._processes.values())[0]
241243
getattr(executor, function_name)()
244+
worker_process.join()
245+
246+
if function_name == 'terminate_workers' or sys.platform == 'win32':
247+
# On windows, kill and terminate both send SIGTERM
248+
self.assertEqual(worker_process.exitcode, -signal.SIGTERM)
249+
elif function_name == 'kill_workers':
250+
self.assertEqual(worker_process.exitcode, -signal.SIGKILL)
242251

243252
self.assertRaises(queue.Empty, q.get, timeout=1)
244253

@@ -256,7 +265,6 @@ def test_process_pool_executor_terminate_kill_workers_not_started_yet(self):
256265

257266
context_with_mocked_process = multiprocessing.get_context()
258267
with unittest.mock.patch.object(context_with_mocked_process, 'Process') as mock_process:
259-
260268
with futures.ProcessPoolExecutor(max_workers=1, mp_context=context_with_mocked_process) as executor:
261269
# The worker has not been started yet, terminate/kill_workers should basically no-op
262270
getattr(executor, function_name)()

0 commit comments

Comments
 (0)