Not able to get debugpy attach (PID and host & port) working inside Zed code editor
@StellaHuang95 がすでに取り組んでいます。
2025年1月29日 から。
評価
この issue はまだ評価されていません。
説明
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
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/debugpy のほかの issue
-
pydevd_comm.py start_client() does not set TCP_NODELAY on the connections it opens対応中かも @nightcityblade が 50 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
Document "rules"-option対応中かも @nightcityblade が 39 日前に担当しました。 オープンdocumentation
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
wx.EventLoop() deprecation warning対応中かも @nightcityblade が 37 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
debugpy.configure(python=) is not properly documented対応中かも @nightcityblade が 48 日前に担当しました。 オープンdocumentation
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
Adapter bootstrap fails with ConnectionRefusedError on WSL2 VirtioProxy or hostAddressLoopback対応中かも @nightcityblade が 4 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
microsoft/debugpy の issue をすべて見る
似ている issue
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
debpalash/VoiceStudio#2624 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
Make Catch2 optional when `RDK_BUILD_CPP_TESTS=OFF`対応中かも @pechersky が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
-
There are a few redundant calls to `fdesc._setCloseOnExec()`対応中かも @gudnimg が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信