[New-bugs-announce] [issue39764] PyAsyncGenObject causes task.get_stack() raising AttributeError

Lidi Zheng report at bugs.python.org
Wed Feb 26 14:25:53 EST 2020

New submission from Lidi Zheng <lidiz at google.com>:

This issue exists since 3.6.

The implementation of get stack on Task is looking for two attribute [1]: "cr_frame" for coroutines, "gi_frame" for generators (legacy coroutines). However, PyAsyncGenObject provides none of them but "ag_frame" [2].

Fix PR: https://github.com/python/cpython/pull/18669

A simple reproduce:

    def test_async_gen_aclose_compatible_with_get_stack(self):
        async def async_generator():
            yield object()

        async def run():
            ag = async_generator()
            tasks = asyncio.all_tasks()
            for task in tasks:
                # No AttributeError raised


I found this in my project I want to view who created the Tasks.

[1] https://github.com/python/cpython/blob/21da76d1f1b527d62b2e9ef79dd9aa514d996341/Lib/asyncio/base_tasks.py#L27
[2] https://github.com/python/cpython/blob/21da76d1f1b527d62b2e9ef79dd9aa514d996341/Objects/genobject.c#L1329

components: asyncio
messages: 362722
nosy: asvetlov, lidiz, yselivanov
priority: normal
pull_requests: 18025
severity: normal
status: open
title: PyAsyncGenObject causes task.get_stack() raising AttributeError
type: behavior
versions: Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list