Skip to content
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

No equivalent of inspect.getcoroutinestate for PyAsyncGenASend instances #81952

Open
GeeTransit mannequin opened this issue Aug 6, 2019 · 3 comments
Open

No equivalent of inspect.getcoroutinestate for PyAsyncGenASend instances #81952

GeeTransit mannequin opened this issue Aug 6, 2019 · 3 comments
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@GeeTransit
Copy link
Mannequin

GeeTransit mannequin commented Aug 6, 2019

BPO 37771
Nosy @agronholm, @1st1, @graingert, @GeeTransit

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2019-08-06.01:20:30.940>
labels = ['type-bug', '3.8', '3.9']
title = 'No equivalent of `inspect.getcoroutinestate` for PyAsyncGenASend instances'
updated_at = <Date 2021-03-06.17:47:09.352>
user = 'https://github.com/GeeTransit'

bugs.python.org fields:

activity = <Date 2021-03-06.17:47:09.352>
actor = 'graingert'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Demos and Tools']
creation = <Date 2019-08-06.01:20:30.940>
creator = 'GeeTransit'
dependencies = []
files = []
hgrepos = []
issue_num = 37771
keywords = []
message_count = 1.0
messages = ['349093']
nosy_count = 4.0
nosy_names = ['alex.gronholm', 'yselivanov', 'graingert', 'GeeTransit']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue37771'
versions = ['Python 3.8', 'Python 3.9']

@GeeTransit
Copy link
Mannequin Author

GeeTransit mannequin commented Aug 6, 2019

In PEP-525, async generators were introduced. They use .asend() and .athrow() methods that return a "coroutine-like" object - specifically, a PyAsyncGenASend and PyAsyncGenAThrow respectively.

While these "coroutine-like" object implement .send(), .throw(), and .close(), they don't provide any attributes like normal coroutine objects do such as cr_running or cr_await.

When I use inspect.getcoroutinestate(), it raises an AttributeError on how there isn't a cr_running attribute / flag.

There is a workaround I use which is to wrap it with another coroutine as below:

>>> async def async_generator():
...     yield
...
>>> async def wrap_coro(coro):
...     return await coro
>>> agen = async_generator()
>>> asend = wrap_coro(agen.asend(None))

This seems like something that should be changed to make it more inline with normal coroutines / awaitables.

@GeeTransit GeeTransit mannequin added 3.8 only security fixes type-bug An unexpected behavior, bug, or error 3.9 only security fixes labels Aug 6, 2019
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added stdlib Python modules in the Lib dir 3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes and removed 3.9 only security fixes 3.8 only security fixes labels Nov 25, 2023
@iritkatriel
Copy link
Member

Duplicate of #79940.

@iritkatriel iritkatriel closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2023
@gschaffner
Copy link

i think that this may not be a duplicate of GH-79940. if i understand correctly:

  • inspect module does not implement introspection API for asynchronous generators #79940 is about inspecting the state of an async generator object. it was resolved when inspect.getasyncgenstate/inspect.getasyncgenlocals was added.

  • this thread is about inspecting the state of an agen.asend(...) "coroutine-like" object (i.e. PyAsyncGenASend, AKA async_generator_asend on CPython). AFAICT it is still not possible to inspect the state of a PyAsyncGenASend unless you wrap it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants