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