Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 569182c

Browse files
[3.11] gh-113205: test_multiprocessing.test_terminate: Shorter sleep for threadpools (GH-114186) (GH-114223)
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 363dddb commit 569182c

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
@@ -2693,8 +2693,16 @@ def test_make_pool(self):
26932693

26942694
def test_terminate(self):
26952695
# Simulate slow tasks which take "forever" to complete
2696+
sleep_time = support.LONG_TIMEOUT
2697+
2698+
if self.TYPE == 'threads':
2699+
# Thread pool workers can't be forced to quit, so if the first
2700+
# task starts early enough, we will end up waiting for it.
2701+
# Sleep for a shorter time, so the test doesn't block.
2702+
sleep_time = 1
2703+
26962704
p = self.Pool(3)
2697-
args = [support.LONG_TIMEOUT for i in range(10_000)]
2705+
args = [sleep_time for i in range(10_000)]
26982706
result = p.map_async(time.sleep, args, chunksize=1)
26992707
p.terminate()
27002708
p.join()

0 commit comments

Comments
 (0)