https://github.com/python/cpython/commit/5070864e161532a14a596c339d94712663142c33 commit: 5070864e161532a14a596c339d94712663142c33 branch: 3.13 author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com> committer: colesbury <colesb...@gmail.com> date: 2025-03-01T16:46:58Z summary:
[3.13] gh-128364: Fix flaky `test_timeout` test (gh-130724) (gh-130728) gh-128364: Fix flaky `test_timeout` test (gh-130724) (cherry picked from commit cfa0b1dc375e63cde28e61a47108c645b0e74834) Co-authored-by: Sam Gross <colesb...@gmail.com> files: M Lib/test/test_concurrent_futures/test_wait.py M Lib/test/test_concurrent_futures/util.py diff --git a/Lib/test/test_concurrent_futures/test_wait.py b/Lib/test/test_concurrent_futures/test_wait.py index 108cf54bf79e6f..697285779510a9 100644 --- a/Lib/test/test_concurrent_futures/test_wait.py +++ b/Lib/test/test_concurrent_futures/test_wait.py @@ -114,9 +114,8 @@ def test_all_completed(self): def test_timeout(self): short_timeout = 0.050 - long_timeout = short_timeout * 10 - future = self.executor.submit(time.sleep, long_timeout) + future = self.executor.submit(self.event.wait) finished, pending = futures.wait( [CANCELLED_AND_NOTIFIED_FUTURE, @@ -132,6 +131,9 @@ def test_timeout(self): finished) self.assertEqual(set([future]), pending) + # Set the event to allow the future to complete + self.event.set() + class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests, BaseTestCase): diff --git a/Lib/test/test_concurrent_futures/util.py b/Lib/test/test_concurrent_futures/util.py index 3b8ec3e205d5aa..daadb8459c3161 100644 --- a/Lib/test/test_concurrent_futures/util.py +++ b/Lib/test/test_concurrent_futures/util.py @@ -1,5 +1,6 @@ import multiprocessing import sys +import threading import time import unittest from concurrent import futures @@ -46,11 +47,14 @@ def setUp(self): self.t1 = time.monotonic() if hasattr(self, "ctx"): + self.manager = multiprocessing.Manager() + self.event = self.manager.Event() self.executor = self.executor_type( max_workers=self.worker_count, mp_context=self.get_context(), **self.executor_kwargs) else: + self.event = threading.Event() self.executor = self.executor_type( max_workers=self.worker_count, **self.executor_kwargs) @@ -58,6 +62,9 @@ def setUp(self): def tearDown(self): self.executor.shutdown(wait=True) self.executor = None + if hasattr(self, "ctx"): + self.manager.shutdown() + self.manager = None dt = time.monotonic() - self.t1 if support.verbose: _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com