Not able to get debugpy attach (PID and host & port) working inside Zed code editor
@StellaHuang95 is already working on this.
Since Jan 29, 2025.
Assessment
This issue has not been assessed yet.
Description
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
}
}
- Dominant language
- Python
- Stars
- 2.5k
- Forks
- 202
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/debugpy
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
All issues in microsoft/debugpy
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
learningequality/ricecooker#747 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
run-llama/llama_index#23199 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
KhronosGroup/glTF-Blender-IO#2769 ·