Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#1,820 15 bình luận 2 reaction 1 người được giao Xem trên GitHub

@StellaHuang95 đang làm issue này rồi.

Từ ngày 29/1/2025.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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
  }
}
Ngôn ngữ chính
Python
Star
2.5k
Fork
205
Merge trung bình
1 ngày 5 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/debugpy

Tất cả issue của microsoft/debugpy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.