Skip to content

Commit c2a2126

Browse files
[3.12] gh-113205: test_multiprocessing.test_terminate: Shorter sleep for threadpools (GH-114186) (GH-114222)
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. Use shorter sleep time for threadpools, so if a task manages to start, the test doesn't block for long. (cherry picked from commit c1db960) Co-authored-by: Petr Viktorin <[email protected]>
1 parent eb582df commit c2a2126

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Lib/test/_test_multiprocessing.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -2694,8 +2694,16 @@ def test_make_pool(self):
26942694

26952695
def test_terminate(self):
26962696
# Simulate slow tasks which take "forever" to complete
2697+
sleep_time = support.LONG_TIMEOUT
2698+
2699+
if self.TYPE == 'threads':
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
2704+
26972705
p = self.Pool(3)
2698-
args = [support.LONG_TIMEOUT for i in range(10_000)]
2706+
args = [sleep_time for i in range(10_000)]
26992707
result = p.map_async(time.sleep, args, chunksize=1)
27002708
p.terminate()
27012709
p.join()

0 commit comments

Comments
 (0)