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

Breakpoints don't work in threads created after `debugpy.listen()` is called

Abierto
#1,963 5 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
python, vscode
Área
devtools

Línea de trabajo

Comienza ejecutando la reproducción proporcionada multithread_debugging.py con start_listener_at_index=5 y compara los puntos de interrupción de la GUI con breakpoint(). Rastrea la configuración de los hilos alrededor de debugpy.listen(); se considera terminado cuando los puntos de interrupción de la GUI se alcanzan en hilos iniciados tanto antes como después de listen, coincidiendo con el comportamiento esperado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Environment data

  • debugpy version: 1.8.14 / 1.8.17
  • OS and version: Mac OS 15.6.1
  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.12
  • Using VS Code or Visual Studio: Visual Studio Code Version: 1.104.1

Actual behavior

In threads which are started (via threading.Thread.start()) after the call to debugpy.listen(), breakpoints will not work.

Expected behavior

Breakpoints should work in all threads, regardless of when they are started.

Steps to reproduce:

  1. Use the following script:
# multithread_debugging.py

import sys
import threading
from queue import Queue

import debugpy

threads: list[threading.Thread] = []
queues: list[Queue] = []

N_THREADS = 10
POISON_PILL = -1


def handler(q: Queue):
    while True:
        item = q.get()
        print(threading.current_thread(), item)
        if item == POISON_PILL:
            print(threading.current_thread(), "exiting")
            return


def send(i: int, item):
    queues[i].put(item)


def end(i: int, *, wait=False):
    send(i, POISON_PILL)
    if wait:
        threads[i].join()


def end_all():
    for i in range(N_THREADS):
        end(i)
    for t in threads:
        t.join()
    print("all done")


if __name__ == "__main__":
    start_listener_at_index = 0
    if len(sys.argv) >= 2:
        start_listener_at_index = int(sys.argv[1])

    for i in range(10):
        q = Queue()
        t = threading.Thread(target=handler, args=[q])
        threads.append(t)
        queues.append(q)

    for i, t in enumerate(threads):
        if i == start_listener_at_index:
            print(f"starting debug listener before thread {i} starts")
            debugpy.listen(("0.0.0.0", 5680))
        t.start()
  1. Add the following launch configuration:
    {
      "name": "Attach to multithreading example",
      "type": "debugpy",
      "request": "attach",
      "connect": {
        "host": "localhost",
        "port": 5680
      }
    },
  1. Run python -i multithread_debugging.py 5
  2. Add a breakpoint on the print statement in the handler() method.
  3. Run the "Attach to multithreading example" debug configuration.
  4. In the REPL, run: send(0, "foo"). Note that the breakpoint is not triggered.
  5. In the REPL, run: send(4, "foo"). Note that the breakpoint is not triggered.
  6. In the REPL, run send(5, "foo"). Note that the breakpoint IS triggered (because thread 5 is started after the debugpy listen call).

Further notes

If you set the breakpoint using the breakpoint() function, it works in all threads. However, if you set it using the vscode GUI, you get the buggy behaviour described above.

Lenguaje dominante
Python
Estrellas
2.5k
Forks
202
Merge medio
5 d 1 h
PR fusionados (30 d)
1

Guía de contribución

Abrir la guía de contribución

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.