Skip to content

gh-98641: Task group vs gather #103644

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 5 commits into from
Apr 20, 2023

Conversation

why-not-try-calmer
Copy link
Contributor

@why-not-try-calmer why-not-try-calmer commented Apr 20, 2023

The purpose of this PR is to clarify the difference(s) between TaskGroup and gather. There are two possibilities:

  • the usecases of two merely overlap: then this PR should clarify the differences so that the user knows which is the better fit for the situation (the comments made here go somewhat in that direction);
  • the use-cases do coincide or one is included in the other: then this PR should explain why gather has not been deprecated yet (maintaining it for compatibility reasons is fine, but this PR should make it explicit).

The end result should better reflect the point of maintaining the two approaches side by side in Python for the years to come, as it has significant impact on the habits that people might develop when writing concurrent Python.

I apologize for not responding to the events that lead to the closing of the Issue referenced below, I was busy on other things. Having my PR + accompanying Issue closed were a good wake-up call.

@bedevere-bot bedevere-bot added docs Documentation in the Doc dir skip news awaiting review labels Apr 20, 2023
@why-not-try-calmer why-not-try-calmer changed the title Task group comments gh-98641 Task group comments Apr 20, 2023
@why-not-try-calmer why-not-try-calmer changed the title gh-98641 Task group comments gh-98641: Task group vs gather Apr 20, 2023
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.
@gvanrossum gvanrossum merged commit 4898415 into python:main Apr 20, 2023
@gvanrossum
Copy link
Member

[...] 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.

I disagree with this part of your proposed commit message, so I removed it. I don't see any mention of this opinion in the changes themselves to I merged your PR. Thanks for your contribution! The docs are better now.

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

[...] 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.

I disagree with this part of your proposed commit message, so I removed it. I don't see any mention of this opinion in the changes themselves to I merged your PR. Thanks for your contribution! The docs are better now.

Thanks. For my education, what's the status of gather() in the grand scheme of things? Is it going to be maintained for compatibility until deprecation? Because the phrasing of docs -- and my PR didn't affect that -- suggests that the use-case for gather(), beyond mere syntactical convenience, is dim.

@gvanrossum
Copy link
Member

I have no desire to deprecate gather().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants