python / python/cpython

`asyncio.print_call_graph()` loses the call stack at asynchronous generators

Đang mở
#156,980 7 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib topic-asyncio type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Bug report

Bug description:

asyncio.print_call_graph() stops at the first async gen in the await chain and silently drops all of the call stack below it

Repro:

import asyncio

async def deep():
    await asyncio.Event().wait()

async def producer():
    await deep()
    yield 1

async def consumer():
    async for _ in producer():
        pass

async def main():
    t = asyncio.create_task(consumer(), name='consumer')
    await asyncio.sleep(0.05)
    print(asyncio.format_call_graph(t))

asyncio.run(main())

Expected:

* Task(name='consumer', id=0x105be89b0)
  + Call stack:
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/locks.py', line 210, in async Event.wait()
  |   File '/Users/timofeiivankov/cpython/repro.py', line 4, in async deep()
  |   File '/Users/timofeiivankov/cpython/repro.py', line 7, in async generator producer()
  |   File '/Users/timofeiivankov/cpython/repro.py', line 11, in async consumer()

Actual:

* Task(name='consumer', id=0x105b089b0)
  + Call stack:
  |   File '/Users/timofeiivankov/cpython/repro.py', line 11, in async consumer()

Proposed fix: expose the wrapped generator as ag_gen and step over the wrapper through it

Have a fix ready for that

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-156984

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với asyncio.format_call_graph() và reproducer trong issue, bao gồm generator bất đồng bộ producer() và consumer task. Kiểm tra cách call graph duyệt qua chuỗi await và so sánh đầu ra của nó với stack mong đợi. Được xem là hoàn tất khi đầu ra vẫn giữ các frame bên dưới generator bất đồng bộ; PR được liên kết gh-156984 cho biết công việc đã đang được tiến hành.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
devtools
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.