Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add async generators section to asyncio internal docs #135674

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Jun 18, 2025

This documents the implementation details of async generators in asyncio.

Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

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

Well written IMO (apart from a few small grammar things).

I love the flowchart, I had no idea github supports them!

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Sorry for the late review (I have been procrastinating on all sorts of stuff :-( ). Looks good, only a few nits.

[`asyncio`](https://docs.python.org/3/library/asyncio.html) module.

# Task management
Copy link
Member

Choose a reason for hiding this comment

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

IIUC this section only discusses the C version -- can you call that out somehow? Previously that was implied by the opening sentence above but that has changed now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a sentence before both section to clarify that.


The above code will not print "finally executed", because the
async generator `agen` is not fully iterated over
and it is not closed manually by awaiting `agen.aclose()`.
Copy link
Member

Choose a reason for hiding this comment

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

Is agen.aclose() a shortcut for something? You cannot literally do that ('function' object has no attribute 'aclose'). So what should I wrote to close it manually (if I was so inclined)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can do something like this to close it:

async def main():
    g = agen()
    async for i in g:
        break

    await g.aclose()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants