Skip to content

Commit 2d366e1

Browse files
encukouaisk
authored andcommitted
pythongh-113205: test_multiprocessing.test_terminate: Test the API on threadpools (python#114186)
pythongh-113205: test_multiprocessing.test_terminate: Test the API works on threadpools Threads can't be forced to terminate (without potentially corrupting too much state), so the expected behaviour of `ThreadPool.terminate` is to wait for the currently executing tasks to finish. The entire test was skipped in pythonGH-110848 (0e9c364). Instead of skipping it entirely, we should ensure the API eventually succeeds: use a shorter timeout. For the record: on my machine, when the test is un-skipped, the task manages to start in about 1.5% cases.
1 parent 1035112 commit 2d366e1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Lib/test/_test_multiprocessing.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -2693,12 +2693,17 @@ def test_make_pool(self):
26932693
p.join()
26942694

26952695
def test_terminate(self):
2696+
# Simulate slow tasks which take "forever" to complete
2697+
sleep_time = support.LONG_TIMEOUT
2698+
26962699
if self.TYPE == 'threads':
2697-
self.skipTest("Threads cannot be terminated")
2700+
# Thread pool workers can't be forced to quit, so if the first
2701+
# task starts early enough, we will end up waiting for it.
2702+
# Sleep for a shorter time, so the test doesn't block.
2703+
sleep_time = 1
26982704

2699-
# Simulate slow tasks which take "forever" to complete
27002705
p = self.Pool(3)
2701-
args = [support.LONG_TIMEOUT for i in range(10_000)]
2706+
args = [sleep_time for i in range(10_000)]
27022707
result = p.map_async(time.sleep, args, chunksize=1)
27032708
p.terminate()
27042709
p.join()

0 commit comments

Comments
 (0)