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

inspect - getasyncgeneratorstate, getasyncgeneratorlocals #91347

Closed
animateaprogramming mannequin opened this issue Apr 1, 2022 · 3 comments
Closed

inspect - getasyncgeneratorstate, getasyncgeneratorlocals #91347

animateaprogramming mannequin opened this issue Apr 1, 2022 · 3 comments
Labels
3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@animateaprogramming
Copy link
Mannequin

animateaprogramming mannequin commented Apr 1, 2022

BPO 47191
Nosy @tirkarthi

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 2022-04-01.18:40:34.046>
labels = ['type-feature', 'library', '3.10', '3.11']
title = 'inspect - getasyncgeneratorstate, getasyncgeneratorlocals'
updated_at = <Date 2022-04-01.20:20:37.341>
user = 'https://bugs.python.org/animateaprogramming'

bugs.python.org fields:

activity = <Date 2022-04-01.20:20:37.341>
actor = 'xtreak'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2022-04-01.18:40:34.046>
creator = 'animatea.programming'
dependencies = []
files = []
hgrepos = []
issue_num = 47191
keywords = []
message_count = 2.0
messages = ['416505', '416516']
nosy_count = 2.0
nosy_names = ['xtreak', 'animatea.programming']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue47191'
versions = ['Python 3.10', 'Python 3.11']

@animateaprogramming
Copy link
Mannequin Author

animateaprogramming mannequin commented Apr 1, 2022

Create inspect introspection functions for asyncgen.

ASYNCGEN_CREATED = 'ASYNCGEN_CREATED'
ASYNCGEN_RUNNING = 'ASYNCGEN_RUNNING'
ASYNCGEN_SUSPENDED = 'ASYNCGEN_SUSPENDED'
ASYNCGEN_CLOSED = 'ASYNCGEN_CLOSED'

def getasyncgeneratorstate(asyncgenerator):
    """Get current state of a async generator-iterator.

    Possible states are:
      ASYNCGEN_CREATED: Waiting to start execution.
      ASYNCGEN_RUNNING: Currently being executed by the interpreter.
      ASYNCGEN_SUSPENDED: Currently suspended at a yield expression.
      ASYNCGEN_CLOSED: Execution has completed.
    """
    if asyncgenerator.ag_running:
        return ASYNCGEN_RUNNING
    if asyncgenerator.ag_frame is None:
        return ASYNCGEN_CLOSED
    if asyncgenerator.ag_frame.f_lasti == -1:
        return ASYNCGEN_CREATED
    return ASYNCGEN_SUSPENDED


def getasyncgeneratorlocals(asyncgenerator):
    """
    Get the mapping of async generator local variables to their current values.

    A dict is returned, with the keys the local variable names and values the
    bound values."""

    if not isasyncgen(asyncgenerator):
        raise TypeError("{!r} is not a Python generator".format(asyncgenerator))

    frame = getattr(asyncgenerator, "ag_frame", None)
    if frame is not None:
        return asyncgenerator.ag_frame.f_locals
    else:
        return {}

@animateaprogramming animateaprogramming mannequin added 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Apr 1, 2022
@tirkarthi
Copy link
Member

Seems to be duplicate of https://bugs.python.org/issue35759

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@kumaraditya303
Copy link
Contributor

Duplicate of #79940

@kumaraditya303 kumaraditya303 marked this as a duplicate of #79940 Jun 20, 2022
@kumaraditya303 kumaraditya303 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants