Memory leak when debugging `asyncio.create_subprocess_shell` calls
@judej ya está trabajando en esto.
Desde el 1/4/2025.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
Environment data
- debugpy version: 2025.4.1
- OS and version: MacOS 14.4
- Python version (& distribution if applicable, e.g. Anaconda): Python 3.13.2
Actual behavior
When debugging code that repeatedly calls asyncio.create_subprocess_shell, memory usage increases over time.
import asyncio
async def do_update(cmd: str):
while True:
process = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
stdout, stderr = await process.communicate()
if process.returncode != 0:
raise Exception(stderr.decode())
print(stdout)
await asyncio.sleep(0.1)
if __name__ == "__main__":
task = asyncio.run(do_update("ps aux | grep bash"))
Expected behavior
When running the above code directly with python (e.g. no debugger), there is no memory leak. The create_subprocess_shell creates a new thread each time it's called, and some cursory debugging of allocations shows mostly thread related things. My suspicion is that the leak is related to thread creation, and that this case is especially bad because asyncio is creating (and destroying) a new thread for each call.
This issue is very severe: a simple application making repeated shell calls will leak memory >1gb running overnight - I also see idle CPU usage at 100% by this point, which I assume is related to the memory issue, but ofc I'm not totally sure.
Steps to reproduce:
- Run example code while debugging with debugpy, watch memory usage of python process.
- Lenguaje dominante
- Python
- Estrellas
- 2.5k
- Forks
- 205
- Merge medio
- 1 d 9 h
- PR fusionados (30 d)
- 3
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/debugpy
-
pydevd_comm.py start_client() does not set TCP_NODELAY on the connections it opensPosiblemente ocupada @nightcityblade la tomó hace 50 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Document "rules"-optionPosiblemente ocupada @nightcityblade la tomó hace 38 días. Abiertodocumentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
wx.EventLoop() deprecation warningPosiblemente ocupada @nightcityblade la tomó hace 37 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
debugpy.configure(python=) is not properly documentedPosiblemente ocupada @nightcityblade la tomó hace 48 días. Abiertodocumentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
Adapter bootstrap fails with ConnectionRefusedError on WSL2 VirtioProxy or hostAddressLoopbackPosiblemente ocupada @nightcityblade la tomó hace 4 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
Todos los issues de microsoft/debugpy
Issues similares
-
json_params_matcher fails on falsy top-level JSON primitives (0, False, "")Posiblemente ocupada @mayureshsonawane17 la tomó hoy. AbiertoWaiting for: Product Owner
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 5 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
第二章思考题 8:Skill 追加到末尾不必每轮重新计算 KVAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
bojieli/ai-agent-book#1169 ·
Los mantenedores suelen responder en 1 día
-
priority:low ready-for-dev
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
OpenHands/extensions#738 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
micronaut-projects/micronaut-core#13677 ·
Los mantenedores suelen responder en 1 día