Skip to content

gh-128364: Fix flaky test_concurrent_futures.test_wait tests #130742

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

Merged
merged 4 commits into from
Mar 6, 2025

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Mar 1, 2025

Use events instead of relying on time.sleep(). The tests are also now about four times faster.

Use events instead of relying on `time.sleep()`. The tests are also now about
four times faster.
@colesbury

This comment was marked as resolved.

@bedevere-bot

This comment was marked as resolved.

@colesbury colesbury added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Mar 1, 2025
@bedevere-bot

This comment was marked as resolved.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Mar 1, 2025
@colesbury

This comment was marked as resolved.

@bedevere-bot

This comment was marked as resolved.

@colesbury colesbury marked this pull request as ready for review March 1, 2025 20:26
@colesbury colesbury requested a review from picnixz March 1, 2025 20:26
Comment on lines +112 to +113
event = self.create_event()
future1 = self.executor.submit(event.wait)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it could be more helpful, but what about using self.addCleanup(event.set) and self.addCleanup(future1.result) here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup functions are called too late. They run after tearDown() where we shutdown the executor and manager.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right..

@@ -50,14 +51,19 @@ def setUp(self):
max_workers=self.worker_count,
mp_context=self.get_context(),
**self.executor_kwargs)
self.manager = multiprocessing.Manager()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using multiprocessing.Manager() and not self.get_context().Manager() actually?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched to self.get_context().Manager().

@colesbury colesbury requested a review from picnixz March 3, 2025 14:14
@@ -42,8 +42,12 @@ def test_first_completed(self):
self.assertEqual(set([future1]), done)
self.assertEqual(set([CANCELLED_FUTURE, future2]), not_done)

event.set()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use maybe try/finally to unblock the task on test failure? Same remark for other tests.

@@ -67,9 +84,14 @@ def test_first_exception(self):
self.assertEqual(set([future1, future2]), finished)
self.assertEqual(set([future3]), pending)

t.join()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use maybe threading_helper.join_thread(t) (from test.support.threading_helper) to not wait forever if something goes wrong.

@colesbury colesbury requested a review from vstinner March 5, 2025 19:32
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the update.

@colesbury colesbury added the needs backport to 3.13 bugs and security fixes label Mar 6, 2025
@colesbury
Copy link
Contributor Author

!buildbot iOS

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @colesbury for commit 0a94b54 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F130742%2Fmerge

The command will test the builders whose names match following regular expression: iOS

The builders matched are:

  • iOS ARM64 Simulator PR

@colesbury colesbury merged commit c4d37ee into python:main Mar 6, 2025
39 checks passed
@colesbury colesbury deleted the gh-128364-flaky-futures-wait-v2 branch March 6, 2025 17:31
@miss-islington-app
Copy link

Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app
Copy link

Sorry, @colesbury, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker c4d37eefb7b33f10f776183447af44faf8efa7f6 3.13

colesbury added a commit to colesbury/cpython that referenced this pull request Mar 6, 2025
… tests (pythongh-130742)

Use events instead of relying on `time.sleep()`. The tests are also now about
four times faster.
(cherry picked from commit c4d37ee)

Co-authored-by: Sam Gross <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Mar 6, 2025

GH-130922 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 6, 2025
colesbury added a commit that referenced this pull request Mar 6, 2025
…gh-130742) (#130922)

Use events instead of relying on `time.sleep()`. The tests are also now about
four times faster.
(cherry picked from commit c4d37ee)
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 RHEL8 Refleaks 3.13 (tier-1) has failed when building commit 0c088e4.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1385/builds/659) and take a look at the build logs.
  4. Check if the failure is related to this commit (0c088e4) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1385/builds/659

Failed tests:

  • test.test_multiprocessing_spawn.test_manager

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/process.py", line 313, in _bootstrap
    self.run()
    ~~~~~~~~^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/_test_multiprocessing.py", line 1580, in f
    woken.release()
    ~~~~~~~~~~~~~^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 1066, in release
    return self._callmethod('release')
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 847, in _callmethod
    raise convert_to_error(kind, result)
multiprocessing.managers.RemoteError: 
---------------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 263, in serve_client
    self.id_to_local_proxy_obj[ident]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: '7f52587f4920'


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 265, in serve_client
    raise ke
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 259, in serve_client
    obj, exposed, gettypeid = id_to_obj[ident]
                              ~~~~~~~~~^^^^^^^
KeyError: '7fdc681c8d80'
---------------------------------------------------------------------------
Timeout (0:45:00)!
Thread 0x00007f930e764240 (most recent call first):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/popen_fork.py", line 28 in poll
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/popen_fork.py", line 44 in wait
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/process.py", line 149 in join
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/case.py", line 614 in _callCleanup
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/case.py", line 688 in doCleanups
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/case.py", line 655 in run
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/case.py", line 707 in __call__
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/suite.py", line 122 in run
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/suite.py", line 84 in __call__
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/suite.py", line 122 in run
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/suite.py", line 84 in __call__
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/runner.py", line 240 in run
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 57 in _run_suite
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 37 in run_unittest
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 135 in test_func
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/refleak.py", line 132 in runtest_refleak
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 87 in regrtest_runner
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 138 in _load_run_test
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 181 in _runtest_env_changed_exc
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 281 in _runtest
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 310 in run_single_test
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/worker.py", line 77 in worker_process
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/worker.py", line 112 in main
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/worker.py", line 116 in <module>
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/runpy.py", line 88 in _run_code
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/runpy.py", line 198 in _run_module_as_main


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 265, in serve_client
    raise ke
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 259, in serve_client
    obj, exposed, gettypeid = id_to_obj[ident]
                              ~~~~~~~~~^^^^^^^
KeyError: '7f52587f4920'
---------------------------------------------------------------------------
k


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 265, in serve_client
    raise ke
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 259, in serve_client
    obj, exposed, gettypeid = id_to_obj[ident]
                              ~~~~~~~~~^^^^^^^
KeyError: '7ff9515d8d80'
---------------------------------------------------------------------------
Timeout (0:45:00)!
Thread 0x00007f0fb1642240 (most recent call first):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/popen_fork.py", line 28 in poll
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/popen_fork.py", line 44 in wait
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/process.py", line 149 in join
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/case.py", line 614 in _callCleanup
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/case.py", line 688 in doCleanups
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/case.py", line 655 in run
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/case.py", line 707 in __call__
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/suite.py", line 122 in run
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/suite.py", line 84 in __call__
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/suite.py", line 122 in run
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/suite.py", line 84 in __call__
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/unittest/runner.py", line 240 in run
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 57 in _run_suite
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 37 in run_unittest
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 135 in test_func
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/refleak.py", line 132 in runtest_refleak
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 87 in regrtest_runner
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 138 in _load_run_test
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 181 in _runtest_env_changed_exc
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 281 in _runtest
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/single.py", line 310 in run_single_test
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/worker.py", line 77 in worker_process
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/worker.py", line 112 in main
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/libregrtest/worker.py", line 116 in <module>
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/runpy.py", line 88 in _run_code
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/runpy.py", line 198 in _run_module_as_main


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/process.py", line 313, in _bootstrap
    self.run()
    ~~~~~~~~^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/_test_multiprocessing.py", line 1580, in f
    woken.release()
    ~~~~~~~~~~~~~^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 1066, in release
    return self._callmethod('release')
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 847, in _callmethod
    raise convert_to_error(kind, result)
multiprocessing.managers.RemoteError: 
---------------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 263, in serve_client
    self.id_to_local_proxy_obj[ident]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: '7ff9515d8d80'


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/process.py", line 313, in _bootstrap
    self.run()
    ~~~~~~~~^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/_test_multiprocessing.py", line 1580, in f
    woken.release()
    ~~~~~~~~~~~~~^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 1066, in release
    return self._callmethod('release')
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 847, in _callmethod
    raise convert_to_error(kind, result)
multiprocessing.managers.RemoteError: 
---------------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 263, in serve_client
    self.id_to_local_proxy_obj[ident]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: '7f71372f0d80'


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/process.py", line 313, in _bootstrap
    self.run()
    ~~~~~~~~^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/test/_test_multiprocessing.py", line 1580, in f
    woken.release()
    ~~~~~~~~~~~~~^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 1066, in release
    return self._callmethod('release')
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 847, in _callmethod
    raise convert_to_error(kind, result)
multiprocessing.managers.RemoteError: 
---------------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 263, in serve_client
    self.id_to_local_proxy_obj[ident]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: '7fdc681c8d80'


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 265, in serve_client
    raise ke
  File "/home/buildbot/buildarea/3.13.cstratak-RHEL8-x86_64.refleak/build/Lib/multiprocessing/managers.py", line 259, in serve_client
    obj, exposed, gettypeid = id_to_obj[ident]
                              ~~~~~~~~~^^^^^^^
KeyError: '7f71372f0d80'
---------------------------------------------------------------------------
k

seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
…ythongh-130742)

Use events instead of relying on `time.sleep()`. The tests are also now about
four times faster.
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.

4 participants