Skip to content

Commit

Permalink
[3.12] gh-113205: test_multiprocessing.test_terminate: Shorter sleep …
Browse files Browse the repository at this point in the history
…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 <encukou@gmail.com>
  • Loading branch information
miss-islington and encukou committed Jan 18, 2024
1 parent eb582df commit c2a2126
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2694,8 +2694,16 @@ def test_make_pool(self):

def test_terminate(self):
# Simulate slow tasks which take "forever" to complete
sleep_time = support.LONG_TIMEOUT

if self.TYPE == 'threads':
# Thread pool workers can't be forced to quit, so if the first
# task starts early enough, we will end up waiting for it.
# Sleep for a shorter time, so the test doesn't block.
sleep_time = 1

p = self.Pool(3)
args = [support.LONG_TIMEOUT for i in range(10_000)]
args = [sleep_time for i in range(10_000)]
result = p.map_async(time.sleep, args, chunksize=1)
p.terminate()
p.join()
Expand Down

0 comments on commit c2a2126

Please sign in to comment.