MagicStack / MagicStack/uvloop
Spawning a subprocess crashes the interpreter if subinterpreters exist
Open
Nobody has claimed this yet.
bug
- Dominant language
- Cython
- Stars
- 11.9k
- Forks
- 616
- PR merge metrics
- No merged PRs in 30d
Description
- uvloop version: 0.21.0
- Python version: 3.13.0
- Platform: Linux
- Can you reproduce the bug with
PYTHONASYNCIODEBUGin 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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied MWE with uvloop 0.21.0 and Python 3.13.0 on Linux, then compare it with vanilla asyncio. Inspect the subprocess path involving uvloop.new_event_loop and uvloop.loop, using asyncio/subprocess.py line 224 and the reported crash as the reproduction and completion criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100