Skip to content

asyncio: expose the Future in FutureIter for introspection? #158192

Description

@msullivan

Feature or enhancement

Proposal:

I am aiming to do some introspection in order to find the Future that an async generator is blocked on.

If it is blocked on a _PyFuture, chasing down the chain of cr_awaits and ag_awaits eventually gets to a generator for Future.__await__, from which self could be extracted from the frame.

But more realistically, it is blocked on a C future, and the chain leads to a FutureIter object. The FutureIter has a future member, but it isn't exposed.

It would be pretty easy to expose it; could we? As fi_future, maybe? No strong opinion on the name.

The most annoying question is what to do about the _PyFuture version: should it stay as it is, and introspection would have to look at the frame, or should it match the C version and expose it as an attribute?

The implementation of this is super straightforward; I can put up a PR if we think we want to do this.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. picnixz commented on Sep 26, 2026

    @picnixz
    Member

    Exposing it also means that we don't want users to actually mess with it I think. It could be good for debugging but it may be an unstable API that may or may not be reliably protected (like, we don't want UAFs etc. The fact that we expose it to pure Python means adding more checks possibly).

    cc @kumaraditya303

  2. 1st1 commented on Sep 28, 2026

    @1st1
    Member

    I don't see why we shouldn't expose it. If this thought occurred to me back in the time when i was adding the C version I'd just do this.

  3. msullivan commented on Sep 30, 2026

    @msullivan
    ContributorAuthor

    Exposing it also means that we don't want users to actually mess with it I think. It could be good for debugging but it may be an unstable API that may or may not be reliably protected (like, we don't want UAFs etc. The fact that we expose it to pure Python means adding more checks possibly).

    cc @kumaraditya303

    There's already some existing unsafety in the concurrent handling of future; #158468 cleans that up, and then my PR for this will depend on that

  4. added a commit that references this issue on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions