You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Please restore the loop param to staggered.staggered_race #124639
asyncio.staggered_race should not be used directly. It is a private API that is not documented anywhere in the documentation. If you want to use staggered_race, please install the 3rd party package async-stagger: https://github.com/twisteroidambassador/async_stagger.
FWIW, there was no deprecation emitted. That got removed right before the PR got merged. @Eclips4 should we reopen this? I guess this is too much of a breaking change for a patch release.
@bdraco, we're going to add back the loop parameter for 3.12. (I'm not sure what the deprecation plan is, I think it's supposed to be 3.14?)
Anyways, this will allow use of eager_task_factory on prior aiohttp versions. However, we're officially marking staggered_race as a private API (and will rename it to _staggered_race). Please copy the current implementation into third parties for future use, as we're not guaranteeing any future support past 3.12 (or maybe 3.13, I think that's undecided).
What's the purpose of the loop kwarg here? Is it to avoid an expensive call to get_running_loop? If so adding the assertion will just remove that perf fix
What's the purpose of the loop kwarg here? Is it to avoid an expensive call to get_running_loop? If so adding the assertion will just remove that perf fix
At this point the concern is historical compatibility only as get_running_loop is so much faster in newer cpython.
The new implementation doesn't seem to handle multiple winners in the same iteration of the event loop as we received aio-libs/aiohappyeyeballs#100 today
Traceback (most recent call last):
File "/opt/homebrew/Caskroom/miniforge/base/envs/work/lib/python3.12/site-packages/aiohappyeyeballs/_staggered.py", line 85, in run_one_coro
assert winner_index is None # noqa: S101
^^^^^^^^^^^^^^^^^^^^
AssertionError
I would like to concur with @bdraco that the new implementation (the one being reverted here) does not handle multiple winners.
This implementation cancels the entire task group by raising an exception when a coroutine wins. This cancellation is not immediate, in the sense that other tasks in the same group may get chances to run before being cancelled, which may result in multiple winners.
Activity
Eclips4 commentedon Sep 26, 2024
Hello!
Thanks for the report.
asyncio.staggered_raceshould not be used directly. It is a private API that is not documented anywhere in the documentation. If you want to usestaggered_race,please install the 3rd party package async-stagger: https://github.com/twisteroidambassador/async_stagger.bdraco commentedon Sep 26, 2024
Its a bit unexpected to have deprecation warnings in it given its not intended for public use. Its also not possible to use https://github.com/twisteroidambassador/async_stagger since it only supports python 3.11+ https://github.com/twisteroidambassador/async_stagger/blob/e09eeefd5d5c123d79abb8ac7f1b5583e8ff3203/setup.py#L30
ZeroIntensity commentedon Sep 26, 2024
FWIW, there was no deprecation emitted. That got removed right before the PR got merged. @Eclips4 should we reopen this? I guess this is too much of a breaking change for a patch release.
ZeroIntensity commentedon Sep 26, 2024
@bdraco, we're going to add back the
loopparameter for 3.12. (I'm not sure what the deprecation plan is, I think it's supposed to be 3.14?)Anyways, this will allow use of
eager_task_factoryon prior aiohttp versions. However, we're officially markingstaggered_raceas a private API (and will rename it to_staggered_race). Please copy the current implementation into third parties for future use, as we're not guaranteeing any future support past 3.12 (or maybe 3.13, I think that's undecided).24 remaining items
pythonGH-124639: add back loop param to staggered_race (python#124700)
[3.12] GH-124639: add back loop param to staggered_race (GH-124700) (#…
graingert commentedon Sep 29, 2024
What's the purpose of the loop kwarg here? Is it to avoid an expensive call to get_running_loop? If so adding the assertion will just remove that perf fix
bdraco commentedon Sep 29, 2024
At this point the concern is historical compatibility only as get_running_loop is so much faster in newer cpython.
bdraco commentedon Sep 30, 2024
The new implementation doesn't seem to handle multiple winners in the same iteration of the event loop as we received aio-libs/aiohappyeyeballs#100 today
I was able to write a test to simulate the problem https://github.com/aio-libs/aiohappyeyeballs/blob/e3519bbebf2069eee0aff0dfde50689c742ba97f/tests/test_staggered.py#L33
I ended up writing a new implementation for
aiohappyeyeballsthat should work on 3.8-3.13+ https://github.com/aio-libs/aiohappyeyeballs/blob/main/src/aiohappyeyeballs/_staggered.pyRevert "pythonGH-124639: add back loop param to staggered_race (pytho…
gh-124309: Revert eager task factory fix to prevent breaking downstre…
pythongh-124309: Revert eager task factory fix to prevent breaking do…
[3.12] gh-124309: Revert eager task factory fix to prevent breaking d…
kumaraditya303 commentedon Oct 27, 2024
Closing as the change was reverted in all branches
twisteroidambassador commentedon Nov 14, 2024
I would like to concur with @bdraco that the new implementation (the one being reverted here) does not handle multiple winners.
This implementation cancels the entire task group by raising an exception when a coroutine wins. This cancellation is not immediate, in the sense that other tasks in the same group may get chances to run before being cancelled, which may result in multiple winners.
I believe (but haven't checked) that my new implementation is compatible with eager task factories: https://github.com/twisteroidambassador/async_stagger/blob/master/async_stagger/stagger.py
ZeroIntensity commentedon Nov 14, 2024
I thought we fixed this with a separate implementation already.
twisteroidambassador commentedon Nov 15, 2024
Right, I see it now. Thanks!