New submission from Lidi Zheng <li...@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()
            asyncio.create_task(ag.aclose())
            tasks = asyncio.all_tasks()
            for task in tasks:
                # No AttributeError raised
                task.get_stack()

        self.loop.run_until_complete


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 <rep...@bugs.python.org>
<https://bugs.python.org/issue39764>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to