Skip to content

python: the adapter sets DEBUGPY_LOG_DIR for every session, so debugpy's debug log runs inside the program (a log line per logpoint hit, on the hitting thread) #1264

Done

Description

@debugmcpdev

Found while measuring what a logpoint hit costs the program (#1218).

What happens

The Python adapter starts debugpy's adapter process with DEBUGPY_LOG_DIR set to the session's log directory, for every session (packages/adapter-python/src/python-debug-adapter.ts:416; it has been there since July 2025). With that variable set, debugpy turns its own debug logging on inside the program being debugged: it sets PYDEVD_DEBUG=True for the debuggee (debugpy/_vendored/force_pydevd.py:21-23 in debugpy 1.8.20), and pydevd then formats and writes a log line for every message it sends, on the thread that sends it (pydevd_net_command.py:87-88). For a logpoint that is the thread that hit it.

Measured on 2026-11-26 (Windows 11, Python 3.13.12, debugpy 1.8.20, main at ff291452, launch mode): one run of a loop with a logpoint on its body, 76,000 hits, wrote a 15.5 MB debugpy.pydevd.<pid>.log from inside the program and a 7.4 MB adapter log beside it. In a run where the program was kept alive until every line was delivered, the adapter's log reached 57 MB.

Why it matters

Expected

debugpy's debug log is off unless someone asks for it: tied to the server's own debug log level, or to an explicit opt-in, and the troubleshooting docs say how to turn it on.

To check after a change

Re-run the Python cells of the logpoint-cost measurement (cost per hit, and the cost of a logpoint elsewhere in the function) and the delivery check, and compare with the numbers on #1218. Not measured so far: this logging's share of the 24.7 µs, and whether it is the delivery bottleneck. Both need the change first.

Activity

  1. added
    bug
    python
    on Nov 26, 2026
  2. debugmcpdev commented on Nov 29, 2026

    @debugmcpdev
    CollaboratorAuthor

    Another cost of this log, measured on 2026-11-29 for #1384.

    On a two-thread breakpoint loop, 6 of 8 sessions froze with the in-program log on: two threads reach breakpoints together, debugpy announces neither stop, the session says running and wait_for_stop stays pending. With the log off, the same two shapes ran 600 rounds with no freeze. Same target, same server build (f08a5158), Python 3.13.12, debugpy 1.8.20, Windows 11, mains power.

    In that measurement the variable was set in the program's own environment (an attach). The launch path sets it at packages/adapter-python/src/python-debug-adapter.ts:448.

    So turning this log off by default also removes most of the exposure to that freeze. The race itself is in debugpy and stays.

  3. added
    in-progress
    on Nov 29, 2026
  4. removed
    in-progress
    on Nov 29, 2026
  5. debugmcpdev commented on Nov 30, 2026

    @debugmcpdev
    CollaboratorAuthor

    Correction to what I wrote here about the freeze of #1384. I said that debugpy's in-program log is what made that freeze frequent ("6 freezes in 600 rounds with it on, none in 600 with it off"). The comparison does not show that.

    A freeze needs both threads at their breakpoints together, so what counts is how often the second thread got there. With the log on it completed 15 loop iterations across the eight sessions, and 6 of them ended in a freeze. With the log off it completed 4, and none did. Six of fifteen against none of four cannot be told apart (Fisher's exact test, p about 0.18).

    What the runs do show is narrower. Per round, the log-on runs froze more often (6 in 600 against 0 in 600), because the second thread got to run about four times as often with the log on. That is a fact about this harness's tight loop, not about the race. The two runs also differed in more than the log: the harness version, an hour between them, and the power state, which was recorded for one only.

    What stands is the cost of a logpoint hit (26.1 µs with the log, 11.7 µs without), which is what #1264 was about. Whether the log changes how often the freeze happens is open, and #1384 says so. The changelog entry and two code comments carried the same claim; #1397 corrects them.

    (Edited once: my first version of this correction compared loop iterations on one side with wait exits on the other, which made the gap look larger than it is.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpython

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions