https://github.com/python/cpython/commit/569182c4ad5ad4b2bcbdcdef3abb18cdf990dd5a
commit: 569182c4ad5ad4b2bcbdcdef3abb18cdf990dd5a
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: encukou <[email protected]>
date: 2024-01-18T13:49:26+01:00
summary:

[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 c1db9606081bdbe0207f83a861a3c70c356d3704)

Co-authored-by: Petr Viktorin <[email protected]>

files:
M Lib/test/_test_multiprocessing.py

diff --git a/Lib/test/_test_multiprocessing.py 
b/Lib/test/_test_multiprocessing.py
index 310401d59631ec..95ef18958e6378 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -2693,8 +2693,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()

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to