asyncio subprocess spawn does not record the awaiting task
未關閉
還沒有人認領這個 Issue。
stdlib
topic-asyncio
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Lib/asyncio/base_subprocess.py 中的 BaseSubprocessTransport.init 開始,檢查 traceback 中顯示的子程序管線連線路徑。執行提供的 asyncio 重現,並確認內部管線連線工作會為 spawn 工作回報一條「Awaited by」邊,然後驗證該邊會被完成回呼捨棄。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend, operating-systems
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 活躍
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100