asyncio subprocess spawn does not record the awaiting task

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

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

Đánh giá

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

Hướng nghiên cứu

Bắt đầu trong Lib/asyncio/base_subprocess.py tại BaseSubprocessTransport.init và kiểm tra đường dẫn kết nối pipe của subprocess được hiển thị trong traceback. Chạy bản tái hiện asyncio được cung cấp và xác nhận rằng tác vụ kết nối pipe nội bộ báo cáo một cạnh “Awaited by” cho tác vụ spawn, sau đó xác minh rằng cạnh này bị callback hoàn tất loại bỏ.

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

Mô tả

stdlib topic-asyncio type-bug

Bug report

Bug description:

The internal subprocess pipe-connect task registers no awaited_by edge

Repro:

import asyncio, sys

async def main():
    spawn = asyncio.create_task(
        asyncio.create_subprocess_exec(sys.executable, '-c', 'pass',
                                       stdin=asyncio.subprocess.PIPE),
        name='spawn')

    await asyncio.sleep(0)
    await asyncio.sleep(0)

    for t in asyncio.all_tasks() - {asyncio.current_task()}:
        asyncio.print_call_graph(t)

    proc = await spawn
    await proc.wait()

asyncio.run(main())

Actual:

* Task(name='spawn', id=0x103e00b90)
  + Call stack:
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/unix_events.py', line 211, in async _UnixSelectorEventLoop._make_subprocess_transport()
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 1839, in async BaseEventLoop.subprocess_exec()
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/subprocess.py', line 249, in async create_subprocess_exec()
* Task(name='Task-2', id=0x103b7d0a0)
  + Call stack:
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 1753, in async BaseEventLoop.connect_write_pipe()
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/base_subprocess.py', line 188, in async BaseSubprocessTransport._connect_pipes()

Expected:

* Task(name='spawn', id=0x105620b90)
  + Call stack:
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/unix_events.py', line 211, in async _UnixSelectorEventLoop._make_subprocess_transport()
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 1839, in async BaseEventLoop.subprocess_exec()
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/subprocess.py', line 249, in async create_subprocess_exec()
* Task(name='Task-2', id=0x10539d0a0)
  + Call stack:
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 1753, in async BaseEventLoop.connect_write_pipe()
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/base_subprocess.py', line 194, in async BaseSubprocessTransport._connect_pipes()
  + Awaited by:
    * Task(name='spawn', id=0x105620b90)
      + Call stack:
      |   File '/Users/timofeiivankov/cpython/Lib/asyncio/unix_events.py', line 211, in async _UnixSelectorEventLoop._make_subprocess_transport()
      |   File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 1839, in async BaseEventLoop.subprocess_exec()
      |   File '/Users/timofeiivankov/cpython/Lib/asyncio/subprocess.py', line 249, in async create_subprocess_exec()

Proposed fix: register the edge in BaseSubprocessTransport.__init__ and discard it in doe callback

I have a fix ready for that

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
558

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.

Issue khác của python/cpython

Tất cả issue của python/cpython

Issue tương tự

Thêm issue về Python

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.