Skip to content

Bug: Stop action missing when attaching to debugpy (e.g. in VSCode) #2098

Done

Description

@summerelm

Environment data

  • debugpy version: 1.8.21
  • OS and version: macOS 15.7.9 (x64)
  • Python version: CPython 3.12.3
  • Using VS Code or Visual Studio: VS Code 1.130.0 (x64), commit 1b6a188127eeaf9194f945eb6eb89a657e93c54c

Actual behavior

  1. In a local Python attach session, the Debug toolbar shows a Disconnect button.
  2. Disconnecting ends the session and leaves the target running.

Expected behavior

  1. The attach toolbar should offer Stop as an alternative to Disconnect.
  2. Stop should terminate the attached Python process.
  3. Disconnect should leave it running.

Steps to reproduce:

  1. Open an empty folder in desktop VS Code with the Python Debugger extension enabled.
    a. Set debug.toolBarLocation to floating in workspace settings so it is easy to see the toolbar.
  2. Save this as heartbeat.py.
import os
import time
from itertools import count

import debugpy

debugpy.listen(("127.0.0.1", 5678))
print(f"Ready to attach (PID {os.getpid()})", flush=True)
debugpy.wait_for_client()

for tick in count():
    print(f"Heartbeat {tick} (PID {os.getpid()})", flush=True)
    time.sleep(1)
  1. Run the script from a terminal in that folder.
python3.12 -m venv .venv
.venv/bin/python -m pip install debugpy==1.8.21
.venv/bin/python -X frozen_modules=off heartbeat.py
  1. Wait for Ready to attach, select Attach to heartbeat in Run and Debug, and press F5. Wait for the script to start printing heartbeats.
  2. Observe that only Disconnect is offered as an option.
  3. Observe that the same PID keeps printing after Disconnect is clicked.

Screenshots

  1. The active attach session shows the Disconnect control at the right end of the debug toolbar (no Stop)
attach-toolbar
  1. After clicking Disconnect, the hearbeat keeps printing
image

Suggested Next Step

Diagnosis

VS Code's protocol uses supportTerminateDebuggee https://github.com/microsoft/vscode/blob/733a99842b0e0e14c3593dfab31fff2035478ba0/src/vs/workbench/contrib/debug/common/debugProtocol.d.ts#L1806

However, debugpy's adapter sends an extra s insupportsTerminateDebuggee

"supportsTerminateDebuggee": True,

Suggested Solution

Change https://github.com/microsoft/debugpy/blob/v1.8.21/src/debugpy/adapter/clients.py#L194 to supportTerminateDebuggee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions