-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Please restore the loop param to staggered.staggered_race #124639
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
Comments
Hello!
|
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 |
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 Anyways, this will allow use of |
Thank you! |
@Eclips4 are you working on this? Or should I write a patch (sorry, should have clarified yesterday). |
Where was this decided? was this discussed at the ongoing sprints? |
On Discord. @ambv said it, I think? |
I don't agree with adding back loop parameter and ignoring it, it is wrong to do. |
I'm sorry, but our backward compatibility and change policy (https://peps.python.org/pep-0387/) is clear in this. The original PR (#124390) makes changes that are not suitable for backport, and that includes both 3.12 and 3.13 (at this point). It's also not suitable to do in 3.14 without a deprecation period or an exemption to the policy (see the last item in https://peps.python.org/pep-0387/#basic-policy-for-backwards-compatibility), but that's @hugovk's call. Please roll back the changes in 3.12 and 3.13, since releases are coming this tuesday. |
Thank you, Thomas, for your feedback on this! |
I have no opinion on the bugfix, but the removal of a keyword argument from a non-private API can't happen in the backport (and can't happen in main without following PEP 387). |
@Yhg1s is it needed to revert the whole fix? The nicer option would be to add |
I am adding back the loop param but the PR doesn't ignores it completely, it actually uses it. This is the best fix for the time being. |
FWIW, this doesn't affect 3.13 yet, because gh-124573 hasn't been merged. |
That's what I suggested on Discord. |
But IIUC there's a 3.12 release planned for Tuesday too, and that is affected. I am still unclear on the use case for passing loop=. The test (which existed before this changed and which Kumar is proposing to restore as part of the fix here) just passes a loop that becomes the current loop by the time anything runs. How is aiohttp using the loop= argument? I would love to see a test that creates a multi-loop scenario similar to what aiohttp uses, and that passes in older 3.12 releases. We can then check if the same test passes in updated 3.12+ branches. This feels urgent because of the expected 3.12 release. If we can't get confidence that Kumar's hack (patching Maybe someone should at least try Kumar's #124700 with an earlier (unpatched) aiohttp version? |
In cpython/Lib/asyncio/base_events.py Line 1020 in 63e54e6
The primary concern was that users who upgrade to a cpython with the new implementation that drops the It mitigate that risk, we removed passing I will test #124700 with aiohappyeyeballs 2.4.0 which was the last version to pass the |
I patched a production system using
|
Thank you for looking at this. I hope that I have explained it well enough. |
Yes, thanks! So it really is the case that the loop passed in must be the currently running loop. Maybe instead of hacking assert loop is None or loop is events.get_running_loop() (or better, some kind of check that raises a I tried modifying the test to use |
(cherry picked from commit e0a41a5) Co-authored-by: Kumar Aditya <kumaraditya@python.org>
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
I was able to write a test to simulate the problem https://github.com/aio-libs/aiohappyeyeballs/blob/e3519bbebf2069eee0aff0dfde50689c742ba97f/tests/test_staggered.py#L33 loop = asyncio.get_running_loop()
winners = []
finish = loop.create_future()
async def coro(idx):
await finish
winners.append(idx)
return idx
coros = [partial(coro, idx) for idx in range(4)]
task = loop.create_task(staggered_race(coros, delay=0.00001))
await asyncio.sleep(0.1)
loop.call_soon(finish.set_result, None)
winner, index, excs = await task I ended up writing a new implementation for |
…wnstream (pythonGH-124810) * Revert "pythonGH-124639: add back loop param to staggered_race (pythonGH-124700)" This reverts commit e0a41a5. * Revert "pythongh-124309: Modernize the `staggered_race` implementation to support eager task factories (pythonGH-124390)" This reverts commit de929f3. (cherry picked from commit 133e929) Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
…ownstream (GH-124810) (#124817) gh-124309: Revert eager task factory fix to prevent breaking downstream (GH-124810) * Revert "GH-124639: add back loop param to staggered_race (GH-124700)" This reverts commit e0a41a5. * Revert "gh-124309: Modernize the `staggered_race` implementation to support eager task factories (GH-124390)" This reverts commit de929f3. (cherry picked from commit 133e929) Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Closing as the change was reverted in all branches |
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 |
I thought we fixed this with a separate implementation already. |
Right, I see it now. Thanks! |
Bug report
Bug description:
The following remove the
loop
param fromstaggered.staggered_race
:#124390
#124574
#124573
its wasn't scheduled for removal until 3.16this never mergedCPython versions tested on:
3.12, 3.13, CPython main branch
Operating systems tested on:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: