Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.d/1264.fixed.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**A launched Python program no longer runs with debugpy's debug log on** — the adapter started debugpy with `DEBUGPY_LOG_DIR` set to the session's log directory for every launch, and debugpy then turns its debug log on inside the debugged program as well: pydevd writes a line for every message it sends, on the program's own threads. Measured on one machine, that log was more than half the cost of a logpoint hit (26.1 µs with it, 11.7 µs without), and it made a freeze far more likely when two threads reach breakpoints together (#1384: 6 freezes in 600 rounds with the log on, none in 600 with it off). The adapter no longer sets the variable, and the policy's fallback spawn no longer passes `--log-dir`. To get debugpy's logs, set `DEBUGPY_LOG_DIR` in the server's environment: it passes through. Attach is unchanged: an attached program logs the way it was started. The docs and the `set_breakpoint` description carry the new figures (#1264, #1384)
**A launched Python program no longer runs with debugpy's debug log on** — the adapter started debugpy with `DEBUGPY_LOG_DIR` set to the session's log directory for every launch, and debugpy then turns its debug log on inside the debugged program as well: pydevd writes a line for every message it sends, on the program's own threads. Measured on one machine, that log was more than half the cost of a logpoint hit (26.1 µs with it, 11.7 µs without). The adapter no longer sets the variable, and the policy's fallback spawn no longer passes `--log-dir`. To get debugpy's logs, set `DEBUGPY_LOG_DIR` in the server's environment: it passes through. Attach is unchanged: an attached program logs the way it was started. The docs and the `set_breakpoint` description carry the new figures (#1264)
2 changes: 1 addition & 1 deletion docs/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,4 @@ The launch passes `dapLaunchArgs.env` through the Python adapter to debugpy. mcp
4. The stack trace shows the call hierarchy that led to the current position
5. Expressions are evaluated against the current paused debug context (current frame when available), with the evaluation context defaulting to `'variables'` — reads and arithmetic are reliable, but verify a mutation such as `x = 5` with a follow-up evaluate before relying on it
6. Child processes are debug sessions by default: debugpy's sub-process debugging is on (the last step of [#1081](https://github.com/debugmcp/mcp-debugger/issues/1081)), so every Python child the program starts (`subprocess`, `multiprocessing`, pytest-xdist workers, an autoreloader, a script that shells out to Python) becomes a child debug session of its own: `list_debug_sessions` lists it with `parentSessionId` naming this session, it stops on the breakpoints set on this session before launch (re-sent to it before it runs), and it has its own `get_output` and `close_debug_session`; closing the parent closes its children first. A `wait_for_stop` on this session is a wait on the tree: it reports a child's stop with `sessionId` naming the child (inspect, step and continue with that id) and `children` listing every child session with its state; a child can still be waited on by its own id. Each child parks until it is adopted (about 110 ms from report to its first stop), is a session row, and counts against `DEBUG_MCP_MAX_CHILD_SESSIONS` (default 32 live children per tree; beyond it a child is released and runs undebugged). Opt out per launch with `dapLaunchArgs: { subProcess: false }` (the children run undebugged and the launch answer's warning says so), per attach target with `python -m debugpy --listen … --configure-subProcess false` (or `debugpy.configure(subProcess=False)` in code — the attach request's `subProcess` is inert), or server-wide with `DEBUG_MCP_MAX_CHILD_SESSIONS=0`. The design is [the session tree](../architecture/session-tree.md), built on the handshake measured in [spike-notes-subprocess.md](spike-notes-subprocess.md)
7. debugpy's own logs (`debugpy.*.log`) are off by default. To turn them on for launched sessions, set `DEBUGPY_LOG_DIR` to a directory in the server's environment (for an attach target, pass `--log-to <dir>` or set `DEBUGPY_LOG_DIR` when starting the target). Either switch also turns pydevd's debug log on inside the debugged program, which slows it: leave them off unless you are diagnosing debugpy itself (issues #1264, #1384).
7. debugpy's own logs (`debugpy.*.log`) are off by default. To turn them on for launched sessions, set `DEBUGPY_LOG_DIR` to a directory in the server's environment (for an attach target, pass `--log-to <dir>` or set `DEBUGPY_LOG_DIR` when starting the target). Either switch also turns pydevd's debug log on inside the debugged program, which slows it: leave them off unless you are diagnosing debugpy itself (issue #1264).
2 changes: 1 addition & 1 deletion docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ default, or a `sessions/` directory beside your `--log-file` when you set one:
dap-trace-<sessionId>.ndjson # only with DAP_TRACE=1
```

Some debug engines drop their own logs into that same run directory. Python's debugpy does not write its `debugpy.*.log` files by default: to turn them on for launched sessions, set `DEBUGPY_LOG_DIR` to a directory in the server's environment. Setting `DEBUGPY_LOG_DIR` also turns pydevd's debug log on inside the debugged program, which slows the program and should be left off unless you are diagnosing debugpy itself (issues #1264, #1384).
Some debug engines drop their own logs into that same run directory. Python's debugpy does not write its `debugpy.*.log` files by default: to turn them on for launched sessions, set `DEBUGPY_LOG_DIR` to a directory in the server's environment. Setting `DEBUGPY_LOG_DIR` also turns pydevd's debug log on inside the debugged program, which slows the program and should be left off unless you are diagnosing debugpy itself (issue #1264).

The proxy log follows the server's `--log-level` / `DEBUG_MCP_LOG_LEVEL`, so raise it to
`debug` before reproducing. The server logs the resolved base directory at startup
Expand Down
7 changes: 3 additions & 4 deletions packages/adapter-python/src/python-debug-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,9 @@ export class PythonDebugAdapter extends EventEmitter implements IDebugAdapter {
],
env: {
// DEBUGPY_LOG_DIR is not set here. debugpy also turns its debug log on
// inside the debugged program when it is set: that doubled the cost of a
// logpoint hit and made the freeze of #1384 far more likely (#1264). An
// operator who wants debugpy's logs sets it in the server's environment,
// and it passes through with the rest of process.env.
// inside the debugged program when it is set, which doubled the cost of
// a logpoint hit (#1264). An operator who wants debugpy's logs sets it in
// the server's environment, and it passes through with process.env.
...process.env,
PYTHONUNBUFFERED: '1' // Ensure unbuffered output
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/interfaces/adapter-policy-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ export const PythonAdapterPolicy = {
};
}

// Otherwise, build the debugpy command (no --log-dir: issues #1264, #1384)
// Otherwise, build the debugpy command (no --log-dir: issue #1264)
const pythonPath = payload.executablePath || (process.platform === 'win32' ? 'python' : 'python3');

return {
Expand Down
Loading