asyncio subprocess spawn does not record the awaiting task
Đang mở
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:
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
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.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend, operating-systems
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 45/100