https://github.com/python/cpython/commit/c1db9606081bdbe0207f83a861a3c70c356d3704
commit: c1db9606081bdbe0207f83a861a3c70c356d3704
branch: main
author: Petr Viktorin <[email protected]>
committer: gpshead <[email protected]>
date: 2024-01-17T17:15:29-08:00
summary:

gh-113205: test_multiprocessing.test_terminate: Test the API on threadpools 
(#114186)

gh-113205: test_multiprocessing.test_terminate: Test the API works on 
threadpools

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.

The entire test was skipped in GH-110848 
(0e9c364f4ac18a2237bdbac702b96bcf8ef9cb09).
Instead of skipping it entirely, we should ensure the API eventually succeeds:
use a shorter timeout.

For the record: on my machine, when the test is un-skipped, the task manages to
start in about 1.5% cases.

files:
M Lib/test/_test_multiprocessing.py

diff --git a/Lib/test/_test_multiprocessing.py 
b/Lib/test/_test_multiprocessing.py
index 8e4e0765d46809..6a050fa541db1e 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -2693,12 +2693,17 @@ def test_make_pool(self):
                 p.join()
 
     def test_terminate(self):
+        # Simulate slow tasks which take "forever" to complete
+        sleep_time = support.LONG_TIMEOUT
+
         if self.TYPE == 'threads':
-            self.skipTest("Threads cannot be terminated")
+            # 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
 
-        # Simulate slow tasks which take "forever" to complete
         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