Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Memory leak when debugging `asyncio.create_subprocess_shell` calls

Abierto
#1,884 0 comentarios 1 reacción 1 asignado Ver en GitHub

@judej ya está trabajando en esto.

Desde el 1/4/2025.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

bug needs repro

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:

  1. 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

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/debugpy

Todos los issues de microsoft/debugpy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.