Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-115957: Close coroutine if the TaskGroup is inactive#116009
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
e4ab02f
to6a0265d
Comparearthur-tacca commentedFeb 28, 2024
Thanks for doing this! I was dangerously close to doing it myself even though I really don't have time, just for the kudos of being a "Python contributor", so I'm really glad you did 😄 My comments:
|
Thanks for the comments Arthur! Yeah that makes sense, I will update the wording there. Regarding the test, it raises a RuntimeWarning without the change for me. Maybe we have slightly different configs? But yeah let me try more specifically sending on the coroutine as well. Thanks again! |
arthur-tacca commentedFeb 28, 2024
Sorry, to be honest I haven't actually run the tests (or for that matter cloned the CPython repo at all), I was just reading the test code. If the test suite automatically fails if there's a warning then you can ignore that comment. |
7f28db0
to8e9866e
CompareSorry for tagging but a gentle nudge for reviewing please 🙏@gvanrossum |
Yeah, it's in my queue. |
Got it, thank you 🙏 |
542d7c2
toe7c3a5e
CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It looks like the tests you changed and added still pass even if I comment out the threecoro.close()
calls added to taskgroups.py. While they print the RuntimeWarning message, they don't fail. Could you try to detect the warnings in at least one of the tests?
Doc/library/asyncio-task.rst Outdated
.. versionchanged:: 3.13 | ||
Close the given coroutine if the task group is not active. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I believe that the convention is that a description of the new/changed behavior is added to the main text of the documentation (in this case the two lines right above) and then theversionchanged
directive is used to clarify when this behavior was added or changed. In this case that would be a little redundant but I still feel it's appropriate.
For example, the main text could include information about when a task group is considered inactive (e.g. not yet entered, already finished, or in the process of shutting down).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks for the explanation! I've updated the main text
Doc/whatsnew/3.13.rst Outdated
@@ -185,6 +185,11 @@ Other Language Changes | |||
(Contributed by Sebastian Pipping in :gh:`115623`.) | |||
* When :func:`asyncio.TaskGroup.create_task` is called on an inactive | |||
:class:`asyncio.TaskGroup`, the given coroutine will be closed (which | |||
prevents a :exc:`RuntimeWarning`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'd clarify that the RuntimeWarning is about "coroutine 'blank' was never awaited".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks for the comments! I've updated the wording
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Thanks for the detailed explanations@gvanrossum ! I have updated one of the tests so that it now explicitly captures and asserts no warning. I've tried it on my machine (MacOS) and it is now failing without the change. Please let me know if there is any other improvement I can apply. Thanks! I have made the requested changes; please review again |
Thanks for making the requested changes! @gvanrossum: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks, looks good! The tests pass in CI, one of the tests fails if I undo the changes in taskgroups.py only, so I will merge.
PS. Next time please don't force push. We squash changes when we merge into main anyway, and the force push makes it harder to re-review the code. |
Thanks@gvanrossum for the review and for the note! I will remember not to force push next time 👌 |
Uh oh!
There was an error while loading.Please reload this page.
This PR addresses the issue where when we call
TaskGroup.create_task()
with an inactiveTaskGroup
, we still get aRuntimeWarning
for the coroutine. This change makes sure that the coroutine is closed in this case and updated the tests accordingly.📚 Documentation preview 📚:https://cpython-previews--116009.org.readthedocs.build/