Spawning a subprocess crashes the interpreter if subinterpreters exist

未关闭
#650 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

首先在 Linux 上使用 uvloop 0.21.0 和 Python 3.13.0 运行提供的 MWE,然后将其与 vanilla asyncio 进行比较。检查涉及 uvloop.new_event_loop 和 uvloop.loop 的子进程路径,并以 asyncio/subprocess.py 第 224 行和报告的崩溃作为复现和完成标准。

由索引模型根据 Issue 内容生成。

描述

bug
  • uvloop version: 0.21.0
  • Python version: 3.13.0
  • Platform: Linux
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: yes
  • Does uvloop behave differently from vanilla asyncio? How?: vanilla asyncio doesn't crash

MWE:

import asyncio

import _interpreters as interpreters
import uvloop

async def main():
    interp_id = interpreters.create()
    await asyncio.create_subprocess_exec("sleep", "2")
    interpreters.destroy(interp_id)  # this is never reached


asyncio.run(main(), loop_factory=uvloop.new_event_loop)

Crash log:

Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, after Python initialization and before Python finalization, but the GIL is released (the current Python thread state is NULL)
Python runtime state: initialized

Current thread 0x00007fa5713c8740 (most recent call first):
  File "/usr/lib64/python3.13/asyncio/subprocess.py", line 224 in create_subprocess_exec
  File "/home/alex/workspace/anyio/bug-trio.py", line 8 in main
  File "/usr/lib64/python3.13/asyncio/runners.py", line 118 in run
  File "/usr/lib64/python3.13/asyncio/runners.py", line 194 in run
  File "/home/alex/workspace/anyio/bug-trio.py", line 12 in <module>

Extension modules: uvloop.loop (total: 1)

If I destroy the subinterpreter before spawning the subprocess, it works fine.

主要语言
Cython
星标
11.9k
派生
615
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MagicStack/uvloop 的其他 Issue

查看 MagicStack/uvloop 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。