Skip to content
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

gh-109974: Fix more threading lock_tests race conditions #110089

Merged
merged 2 commits into from
Sep 29, 2023

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Sep 29, 2023

  • Add context manager on Bunch class.
  • Bunch now catchs exceptions on executed functions and re-raise them at exit() as an ExceptionGroup.
  • Rewrite BarrierProxy.test_default_timeout(). Use a single thread. Only check that barrier.wait() blocks for at least default timeout seconds.
  • test_with(): inline _with() function.

* Add context manager on Bunch class.
* Bunch now catchs exceptions on executed functions and re-raise them
  at __exit__() as an ExceptionGroup.
* Rewrite BarrierProxy.test_default_timeout(). Use a single thread.
  Only check that barrier.wait() blocks for at least default timeout
  seconds.
* test_with(): inline _with() function.
@vstinner
Copy link
Member Author

Windows x64 failed with:


0:22:17 load avg: 0.08 [467/467/1] test.test_concurrent_futures.test_shutdown process crashed (Exit code 1)
Timeout (0:10:00)!
Thread 0x00001b44 (most recent call first):
  File "D:\a\cpython\cpython\Lib\subprocess.py", line 1597 in _readerthread
  File "D:\a\cpython\cpython\Lib\threading.py", line 1003 in run
  File "D:\a\cpython\cpython\Lib\threading.py", line 1066 in _bootstrap_inner
  File "D:\a\cpython\cpython\Lib\threading.py", line 1023 in _bootstrap

Thread 0x00000e08 (most recent call first):
  File "D:\a\cpython\cpython\Lib\subprocess.py", line 1597 in _readerthread
  File "D:\a\cpython\cpython\Lib\threading.py", line 1003 in run
  File "D:\a\cpython\cpython\Lib\threading.py", line 1066 in _bootstrap_inner
  File "D:\a\cpython\cpython\Lib\threading.py", line 1023 in _bootstrap

Thread 0x00001a48 (most recent call first):
  File "D:\a\cpython\cpython\Lib\threading.py", line 1160 in _wait_for_tstate_lock
  File "D:\a\cpython\cpython\Lib\threading.py", line 1140 in join
  File "D:\a\cpython\cpython\Lib\subprocess.py", line 1626 in _communicate
  File "D:\a\cpython\cpython\Lib\subprocess.py", line 1209 in communicate
  File "D:\a\cpython\cpython\Lib\test\support\script_helper.py", line 139 in run_python_until_end
  File "D:\a\cpython\cpython\Lib\test\support\script_helper.py", line 149 in _assert_python
  File "D:\a\cpython\cpython\Lib\test\support\script_helper.py", line 166 in assert_python_ok
  File "D:\a\cpython\cpython\Lib\test\test_concurrent_futures\test_shutdown.py", line 32 in test_interpreter_shutdown

@vstinner
Copy link
Member Author

Windows x64 failed with: FAIL: test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_started (test.test_asyncio.test_waitfor.AsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_started).

Good news: PR #110092 is going to fix it.

@vstinner vstinner merged commit 743e357 into python:main Sep 29, 2023
21 checks passed
@vstinner vstinner deleted the lock_tests2 branch September 29, 2023 12:21
vstinner added a commit to vstinner/cpython that referenced this pull request Oct 4, 2023
…n#110089)

* Add context manager on Bunch class.
* Bunch now catchs exceptions on executed functions and re-raise them
  at __exit__() as an ExceptionGroup.
* Rewrite BarrierProxy.test_default_timeout(). Use a single thread.
  Only check that barrier.wait() blocks for at least default timeout
  seconds.
* test_with(): inline _with() function.

(cherry picked from commit 743e357)
vstinner added a commit that referenced this pull request Oct 4, 2023
…110346)

* gh-109974: Fix threading lock_tests race conditions (#110057)

Fix race conditions in test_threading lock tests. Wait until a
condition is met rather than using time.sleep() with a hardcoded
number of seconds.

* Replace sleeping loops with support.sleeping_retry() which raises
  an exception on timeout.
* Add wait_threads_blocked(nthread) which computes a sleep depending
  on the number of threads. Remove _wait() function.
* test_set_and_clear(): use a way longer Event.wait() timeout.
* BarrierTests.test_repr(): wait until the 2 threads are waiting for
  the barrier. Use a way longer timeout for Barrier.wait() timeout.
* test_thread_leak() no longer needs to count
  len(threading.enumerate()): Bunch uses
  threading_helper.wait_threads_exit() internally which does it in
  wait_for_finished().
* Add BaseLockTests.wait_phase() which implements a timeout.
  test_reacquire() and test_recursion_count() use wait_phase().

(cherry picked from commit 4e356ad)

* gh-109974: Fix more threading lock_tests race conditions (#110089)

* Add context manager on Bunch class.
* Bunch now catchs exceptions on executed functions and re-raise them
  at __exit__() as an ExceptionGroup.
* Rewrite BarrierProxy.test_default_timeout(). Use a single thread.
  Only check that barrier.wait() blocks for at least default timeout
  seconds.
* test_with(): inline _with() function.

(cherry picked from commit 743e357)
vstinner added a commit that referenced this pull request Oct 4, 2023
…110355)

[3.12] gh-109974: Fix threading lock_tests race conditions (#110057) (#110346)

* gh-109974: Fix threading lock_tests race conditions (#110057)

Fix race conditions in test_threading lock tests. Wait until a
condition is met rather than using time.sleep() with a hardcoded
number of seconds.

* Replace sleeping loops with support.sleeping_retry() which raises
  an exception on timeout.
* Add wait_threads_blocked(nthread) which computes a sleep depending
  on the number of threads. Remove _wait() function.
* test_set_and_clear(): use a way longer Event.wait() timeout.
* BarrierTests.test_repr(): wait until the 2 threads are waiting for
  the barrier. Use a way longer timeout for Barrier.wait() timeout.
* test_thread_leak() no longer needs to count
  len(threading.enumerate()): Bunch uses
  threading_helper.wait_threads_exit() internally which does it in
  wait_for_finished().
* Add BaseLockTests.wait_phase() which implements a timeout.
  test_reacquire() and test_recursion_count() use wait_phase().

(cherry picked from commit 4e356ad)

* gh-109974: Fix more threading lock_tests race conditions (#110089)

* Add context manager on Bunch class.
* Bunch now catchs exceptions on executed functions and re-raise them
  at __exit__() as an ExceptionGroup.
* Rewrite BarrierProxy.test_default_timeout(). Use a single thread.
  Only check that barrier.wait() blocks for at least default timeout
  seconds.
* test_with(): inline _with() function.

(cherry picked from commit 743e357)
(cherry picked from commit 1d032ea)
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…n#110089)

* Add context manager on Bunch class.
* Bunch now catchs exceptions on executed functions and re-raise them
  at __exit__() as an ExceptionGroup.
* Rewrite BarrierProxy.test_default_timeout(). Use a single thread.
  Only check that barrier.wait() blocks for at least default timeout
  seconds.
* test_with(): inline _with() function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant