]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-113205: test_multiprocessing.test_terminate: Shorter sleep for threadpools...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 18 Jan 2024 12:49:24 +0000 (13:49 +0100)
committerGitHub <noreply@github.com>
Thu, 18 Jan 2024 12:49:24 +0000 (13:49 +0100)
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 c1db9606081bdbe0207f83a861a3c70c356d3704)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Lib/test/_test_multiprocessing.py

index 9ab0f9bc52c80bf82d53312a9d7837bc2f97275d..4cadefe40af71ebc027dcafdf8667b727ddf0697 100644 (file)
@@ -2694,8 +2694,16 @@ class _TestPool(BaseTestCase):
 
     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()