-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_threading
failing randomly on CI
#129266
Comments
The other failure in that same job is
|
Another failure but in multiprocessing https://github.com/python/cpython/actions/runs/12954294733/job/36135983482?pr=129267 test_timeout (test.test_multiprocessing_spawn.test_threads.WithThreadsTestSemaphore.test_timeout) ... skipped 'test not appropriate for threads'
======================================================================
FAIL: test_default_timeout (test.test_multiprocessing_spawn.test_threads.WithThreadsTestBarrier.test_default_timeout)
Test the barrier's default timeout
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\a\cpython\cpython\Lib\test\_test_multiprocessing.py", line 2291, in test_default_timeout
self.assertEqual(len(results), barrier.parties)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 5
----------------------------------------------------------------------
Ran 105 tests in 68.027s
FAILED (failures=1, skipped=27) |
I've run |
Encountered the following locally (while running 5 tests simulataneously):
|
I'm increasingly confident that these are bugs in the test code and not in the threading module or other parts of Python. For example, the test in cpython/Lib/test/lock_tests.py Lines 510 to 527 in e119526
|
I think we should fix these tests to not rely on arbitrary sleeps for synchronization. In the past we had similar issues with using sleeps in asyncio tests so I ended up removing a lot of those and switch to barrier or other sync primitives, the same should be done for threading tests. |
It's not clear how to avoid the sleeps in this test. You need to wait until the other threads are blocked on |
I think in this case we can check the waiter count of the underlying condition used |
I tested the following by adding a artificial delay before waiting on the events in threads and seems to work. diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
index 8c8f8901f00..9e9bbed4f2f 100644
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -513,12 +513,14 @@ def test_set_and_clear(self):
event = self.eventtype()
results = []
def f():
+ time.sleep(0.1)
results.append(event.wait(support.LONG_TIMEOUT))
N = 5
with Bunch(f, N):
# Threads blocked on event.wait()
- wait_threads_blocked(N)
+ while len(event._cond._waiters) != N:
+ time.sleep(0.01)
# Threads unblocked
event.set()
|
See https://github.com/python/cpython/actions/runs/12953185538/job/36134744339?pr=128869
The text was updated successfully, but these errors were encountered: