Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Not able to get debugpy attach (PID and host & port) working inside Zed code editor

オープン
#1,820 コメント 15 件 リアクション 2 件 担当者 1 名 GitHub で見る

@StellaHuang95 がすでに取り組んでいます。

2025年1月29日 から。

評価

この issue はまだ評価されていません。

説明

bug needs repro

Hi debugpy team,

I'm one of the guys that is working on the client-side implementation of the DAP spec for the Zed code editor.

We are struggling a bit to get the attach (PID and host & port) feature to work, and haven't found any documentation on how to do it.
Could you please point me in the right direction to find out how to configure debugpy to work with attach?

About our implementation:

We use the debugpy library that is installed inside the user’s virtual environment. We start the debug adapter with the following command:

path/to/python debugpy.adapter --port=1234 --host=localhost
Our Setup

We start a simple Python script with the following commands:

mkdir test-python-project
cd test-python-project
python3 -m venv ./.venv
source ./.venv/bin/activate
pip install debugpy
touch test.py

Add the following content to the test.py file:

x = 1 // added breakpoint here
print("Script has started")

while True:
    x += 1

Start to listen for debugger:

debugpy --listen localhost:5678 --wait-for-client test.py
Our Issue

So one of the issues we are facing is that we never receive an attach response back, so it seems like debugpy is waiting for something/someone. So I looked at our request/response log which shows that we receive two custom events debugpySockets and debugpyWaitingForServer. Which results into the following error log Cancelled DAP request for "attach" id 2 which took over 12s.

Which to my understanding is not more than just an informational event, to notify us about the sockets it is listening on and that it is waiting for a server to connect to it. So while I was debugging this issue, I looked at the vscode-python-debugger implementation, it seems like they don't really act on these events.

So my first question is should we act on these events? And if so, how should we act on them?
I also read through some of the debugpy internal code, which seems to support the StartDebuggingRequest reverse request, so should we act on these events if we could receive the StartDebuggingRequest request?

I've seen examples online where two instances of debugpy are run, one for the debuggee program and another to connect to the first instance. Is this a pattern that we'll have to replicate?

Request log for debugpy attach
// Send
{
  "type": "request",
  "seq": 1,
  "command": "initialize",
  "arguments": {
    "clientID": "zed",
    "clientName": "Zed",
    "adapterID": "debugpy",
    "locale": "en-US",
    "linesStartAt1": true,
    "columnsStartAt1": true,
    "pathFormat": "path",
    "supportsVariableType": true,
    "supportsVariablePaging": false,
    "supportsRunInTerminalRequest": true,
    "supportsMemoryReferences": true,
    "supportsProgressReporting": false,
    "supportsInvalidatedEvent": false,
    "supportsMemoryEvent": false,
    "supportsArgsCanBeInterpretedByShell": false,
    "supportsStartDebuggingRequest": true
  }
}
// Receive
{
  "seq": 1,
  "type": "event",
  "event": "output",
  "body": {
    "category": "telemetry",
    "output": "ptvsd",
    "data": {
      "packageVersion": "1.8.12"
    }
  }
}
{
  "seq": 2,
  "type": "event",
  "event": "output",
  "body": {
    "category": "telemetry",
    "output": "debugpy",
    "data": {
      "packageVersion": "1.8.12"
    }
  }
}
{
  "seq": 3,
  "type": "event",
  "event": "debugpySockets",
  "body": {
    "sockets": [
      {
        "host": "127.0.0.1",
        "port": 52653,
        "internal": false
      }
    ]
  }
}
{
  "seq": 4,
  "type": "response",
  "request_seq": 1,
  "success": true,
  "command": "initialize",
  "body": {
    "supportsCompletionsRequest": true,
    "supportsConditionalBreakpoints": true,
    "supportsConfigurationDoneRequest": true,
    "supportsDebuggerProperties": true,
    "supportsDelayedStackTraceLoading": true,
    "supportsEvaluateForHovers": true,
    "supportsExceptionInfoRequest": true,
    "supportsExceptionOptions": true,
    "supportsFunctionBreakpoints": true,
    "supportsHitConditionalBreakpoints": true,
    "supportsLogPoints": true,
    "supportsModulesRequest": true,
    "supportsSetExpression": true,
    "supportsSetVariable": true,
    "supportsValueFormattingOptions": true,
    "supportsTerminateRequest": true,
    "supportsGotoTargetsRequest": true,
    "supportsClipboardContext": true,
    "exceptionBreakpointFilters": [
      {
        "filter": "raised",
        "label": "Raised Exceptions",
        "default": false,
        "description": "Break whenever any exception is raised."
      },
      {
        "filter": "uncaught",
        "label": "Uncaught Exceptions",
        "default": true,
        "description": "Break when the process is exiting due to unhandled exception."
      },
      {
        "filter": "userUnhandled",
        "label": "User Uncaught Exceptions",
        "default": false,
        "description": "Break when exception escapes into library code."
      }
    ],
    "supportsStepInTargetsRequest": true
  }
}
// Send
{
  "type": "request",
  "seq": 2,
  "command": "attach",
  "arguments": {
    "request": "attach",
    "cwd": "/Users/remcosmits/Documents/code/test-python-project",
    "type": "debugpy",
    "logToFile": true,
    "connect": {
      "host": "localhost",
      "port": 5678
    },
    "clientOS": "unix",
    "justMyCode": true,
    "showReturnValue": true,
    "workspaceFolder": "/Users/remcosmits/Documents/code/test-python-project"
  }
}
// Receive
{
  "seq": 5,
  "type": "event",
  "event": "debugpySockets",
  "body": {
    "sockets": [
      {
        "host": "127.0.0.1",
        "port": 52653,
        "internal": false
      },
      {
        "host": "127.0.0.1",
        "port": 52656,
        "internal": true
      }
    ]
  }
}
{
  "seq": 6,
  "type": "event",
  "event": "debugpyWaitingForServer",
  "body": {
    "host": "127.0.0.1",
    "port": 52656
  }
}
主要言語
Python
スター
2.5k
フォーク
205
平均マージ
1日 9時間
マージ済み PR(30日)
3

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/debugpy のほかの issue

microsoft/debugpy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。