Skip to content

gh-98641: Don't portray asyncio.TaskGroup as a replacement for asyncio.gather in docs #98659

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

Conversation

why-not-try-calmer
Copy link
Contributor

@why-not-try-calmer why-not-try-calmer commented Oct 25, 2022

The purpose of the comments is to rule out the implication that asyncio.TaskGroup is a drop-in replacement / better alternative to asyncio.gather(). Both have their idiomatic uses cases, and asyncio.gather() works well for tasks that do not schedule tasks themselves, especially when the caller needs to consume their result as soon as possible.

The purpose of the comments is to rule out the implication that asyncio.TaskGroup is a drop-in replacement / better alternative to asyncio.gather(). Both have their idiomatic uses cases, and asyncio.gather() works well for tasks that do not schedule tasks themselves, especially when the caller needs to consume their result as soon as possible.
@zware
Copy link
Member

zware commented Oct 25, 2022

Backports will be handled automatically after the PR against main is merged, no need to try it manually.

@zware zware closed this Oct 25, 2022
@zware
Copy link
Member

zware commented Oct 25, 2022

Oh, sorry; this is the PR against main. Your [3.11] tag confused the bot (and then me :)).

@zware zware reopened this Oct 25, 2022
@zware zware changed the title [3.11] The documentation about asyncio.TaskGroup might portray it as a replacement for asyncio.gather (gh-98641) gh-98641: The documentation about asyncio.TaskGroup might portray it as a replacement for asyncio.gather Oct 25, 2022
@why-not-try-calmer
Copy link
Contributor Author

why-not-try-calmer commented Oct 25, 2022

Oh, sorry; this is the PR against main. Your [3.11] tag confused the bot (and then me :)).

I apologize for the inconvenience. 🙏🏻 Between my fork, the Issue and the PR I probably misread something.

Comment on lines 452 to 455
wait for their completion is :class:`asyncio.TaskGroup`. While *TaskGroup*
provides strong safety guarantees for scheduling a nesting of subtasks, *gather* comes in handy
for tasks that do not schedule subtasks and need to have their results consumed eagerly
(i.e. when destructuring the result(s) into a tuple).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
wait for their completion is :class:`asyncio.TaskGroup`. While *TaskGroup*
provides strong safety guarantees for scheduling a nesting of subtasks, *gather* comes in handy
for tasks that do not schedule subtasks and need to have their results consumed eagerly
(i.e. when destructuring the result(s) into a tuple).
wait for their completion is :class:`asyncio.TaskGroup`. While *TaskGroup*
provides strong safety guarantees for scheduling a nesting of subtasks, *gather* is useful
for tasks that do not schedule subtasks and need to have their results consumed eagerly
(i.e. when destructuring the result(s) into a tuple).

Honestly I'm not sure I agree. If you need the results, you can just await the tasks. The big difference is that gather will not cancel remaining tasks once one task raises. Your description here doesn't call out that difference.

Copy link
Contributor Author

@why-not-try-calmer why-not-try-calmer Oct 25, 2022

Choose a reason for hiding this comment

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

I agree, my formulation didn't address this important point. Instead of committing your suggestion, I have tried to accomodate it, rewording this section of the documentation to better emphasize the difference and uses cases between TaskGroup and gather. I don't want to stretch the text too much as this is not meant to be a tutorial, but I am all ears if this can be improved even more.

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

@why-not-try-calmer
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@gvanrossum: please review the changes made to this pull request.

@gvanrossum gvanrossum changed the title gh-98641: The documentation about asyncio.TaskGroup might portray it as a replacement for asyncio.gather gh-98641: Don't portray asyncio.TaskGroup as a replacement for asyncio.gather in docs Oct 27, 2022
@gvanrossum gvanrossum added the needs backport to 3.11 only security fixes label Oct 27, 2022
@why-not-try-calmer
Copy link
Contributor Author

Sorry, any news about this?

@@ -447,8 +448,15 @@ Running Tasks Concurrently
Tasks/Futures to be cancelled.

.. note::
A more modern way to create and run tasks concurrently and
wait for their completion is :class:`asyncio.TaskGroup`.
A new alternative to create and run tasks concurrently and
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there should be this much information in a note.

Copy link
Contributor Author

@why-not-try-calmer why-not-try-calmer Nov 27, 2022

Choose a reason for hiding this comment

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

Thanks for your comment. It's difficult to turn into something actionable. Can you clarify what you'd remove, bearing in mind the purpose and arguments put forth in this PR?

Copy link
Contributor

@kumaraditya303 kumaraditya303 Nov 27, 2022

Choose a reason for hiding this comment

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

Honestly this belongs more to a FAQ entry than reference docs. But this note was already there, I suggest to only explain the case why gather should be used and keep it short something like "Use asyncio.gather if you want to concurrently run coroutines and cancellation of one does not affects others otherwise it is recommend to use TaskGroups". Feel free to word it better!

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Contributor

@kumaraditya303 kumaraditya303 left a comment

Choose a reason for hiding this comment

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

awaiting changes

@gvanrossum
Copy link
Member

I am closing this, we're not even in agreement on whether there is anything that should be changed here, let alone on how it should be changed.

@gvanrossum gvanrossum closed this Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants