]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-133454: Reduce the number of threads in test_racing_getbuf_and_releasebuf (GH...
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 23 May 2025 16:58:34 +0000 (19:58 +0300)
committerGitHub <noreply@github.com>
Fri, 23 May 2025 16:58:34 +0000 (19:58 +0300)
The original reproducer only used 10 threads.

Lib/test/test_memoryview.py

index 61b068c630c7ce90d8083fcb859d4ebce84690c0..64f440f180bbf0d7963d5f2fa67c827377aec1a6 100644 (file)
@@ -743,19 +743,21 @@ class RacingTest(unittest.TestCase):
             from multiprocessing.managers import SharedMemoryManager
         except ImportError:
             self.skipTest("Test requires multiprocessing")
-        from threading import Thread
+        from threading import Thread, Event
 
-        n = 100
+        start = Event()
         with SharedMemoryManager() as smm:
             obj = smm.ShareableList(range(100))
-            threads = []
-            for _ in range(n):
-                # Issue gh-127085, the `ShareableList.count` is just a convenient way to mess the `exports`
-                # counter of `memoryview`, this issue has no direct relation with `ShareableList`.
-                threads.append(Thread(target=obj.count, args=(1,)))
-
+            def test():
+                # Issue gh-127085, the `ShareableList.count` is just a
+                # convenient way to mess the `exports` counter of `memoryview`,
+                # this issue has no direct relation with `ShareableList`.
+                start.wait(support.SHORT_TIMEOUT)
+                for i in range(10):
+                    obj.count(1)
+            threads = [Thread(target=test) for _ in range(10)]
             with threading_helper.start_threads(threads):
-                pass
+                start.set()
 
             del obj