Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The debugging session fails silently immediately after clicking 'Start Debugging' (On Windows only) #1807

Open
rene-deltares opened this issue Jan 10, 2025 · 3 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@rene-deltares
Copy link

At some point last year, debugging python code in vscode stopped working on my work laptop (running Windows 10). The problem only occurs when I open a folder/workspace in Windows. I mostly work in Linux in VSCode through the WSL remote connection. When connected through WSL, the debugging extension works without problems. I mostly work through WSL, so I ignored the problems I had on Windows. Now, months later, we're experiencing a crash in our Python code that only occurs on Windows. Not being able to run with debugging in Windows VSCode is making it really hard to help out my colleages.

So far I tried reviewing my launch.json and settings.json, updating the extension to the latest version and the latest pre-release version, and checking the 'Python Debugger' output pane.

The problem

I created a few configurations in my launch.json. Some for specific python programs, and one for the pytest test suite. If I click 'Start debugging', nothing much seems to happen:

  • A 'loading bar' and the tiny 'debug' menu (with the continue, step, stop and pause buttons) flash on the screen for a fraction of a second, then disappear.
  • The 'Python Debugger' output shows two new lines:
    • Resolving launch configuration with substituted variables
    • DAP Server launched with command: <my-repo-dir>\.venv\Scripts\python <home-dir>\.vscode\extensions\ms-python.debugpy-2024.15.2024121701-win32-x64\bundled\libs\debugpy\adapter

I configured the test discovery in vscode, and I can run our test suite just fine. But when I click 'Debug test' on any test, the test doesn't run. The spinner seems to run indefinitely. I get the same two lines as above in the 'Python Debugger' output.

I should mention that I have been able to debug with python just fine in the past, and not much has changed in my configuration since (if anything, I don't know if the problem occurred because of a settings change). As far as I can tell I'm using a bogstandard vscode configuration for a simple python project.

Using the logToFile option in launch.json

The only progress I made is to add "logToFile": true to my debug configuration in launch.json. I can tell from the Python Debugger output that the extension is invoking a python program called adapter with an option to write a log file to my home directory (where my vscode extensions are stored). It didn't help me much, but maybe it can be of some help to you, so I'll attach the logfile to this issue.

debugger.vscode_uuid.log

Is there any way to see more verbose output than this? Or is there some other log I could check? I'm kind of stumped at this point, and I could use your help.

My configuration

VSCode:
Version: 1.96.2 (user setup)
Commit: fabdb6a30b49f79a7aba0f2ad9df9b399473380f
Date: 2024-12-19T10:22:47.216Z
Electron: 32.2.6
ElectronBuildId: 10629634
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Windows_NT x64 10.0.19045

VSCode extensions:
ms-python.python: 2024.22.2
ms-python.debugpy: 2024.15.2024121701

Python: 3.12.0

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug my-program",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}\\my-program.py",
            "logToFile": true,
            "args": [
                "--flag",
                "--with=argument"
            ],
            "console": "integratedTerminal",
            "justMyCode": false
        },
        // ...
    ]
}

settings.json

{
    "python.defaultInterpreterPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
    "python.terminal.activateEnvironment": true,
    "python.testing.pytestEnabled": true,
    "python.testing.autoTestDiscoverOnSaveEnabled": true,
    "python.envFile": "${workspaceFolder}\\.env",
    // ...
}

Thanks!

@eleanorjboyd eleanorjboyd transferred this issue from microsoft/vscode-python-debugger Jan 14, 2025
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Jan 14, 2025
@rchiodo
Copy link
Contributor

rchiodo commented Jan 14, 2025

I guess I'd try running debugpy manually from the terminal. It seems like something is crashing on startup.

You could try the specific command line used by VS code:

'c:\Users\rchiodo\source\testing\test_pylance\.venv313\Scripts\python.exe' 'c:\Users\rchiodo\.vscode-insiders\extensions\ms-python.debugpy-2024.15.2024121701-win32-x64\bundled\libs\debugpy\launcher' '53226' '--' 'c:\Users\rchiodo\source\testing\test_pylance\test_debugging.py'

Or you could try something simpler. Install debugpy into your .venv and run this:

python -m debugpy --listen 5678 yourscript.py

And see what happens. That latter command can be attached to from VS code.

@rene-deltares
Copy link
Author

Interesting, it hadn't occurred to me that I could install debugpy from pypi and run it.

So I installed debugpy==1.8.11 in my virtual environment (that version matches the one bundled with the vscode extension), and I start the server like this:

python -m debugpy --listen 5678 --wait-for-client .\my_script.py --flag --with=argument

I use this attach configuration in launch.json

{
  "name": "Attach to adapter",
  "type": "debugpy",
  "request": "attach",
  "connect": {
    "host": "127.0.0.1",
    "port": 5678
  }
}

Now I can set breakpoints in vscode, and when I select the Attach to adapter launch configuration, the debugging works! The program runs and my breakpoints are getting hit in vscode. So at least I now have a workaround for the problem and that's already progress. Thanks!

I don't think I got the launcher program working. I suspect the problem is there, but I'm a bit confused about how I'm supposed to use it. I tried this command:

python '<home_dir>\.vscode\extensions\ms-python.debugpy-2024.15.2024121701-win32-x64\bundled\libs\debugpy\launcher' '53226' '--' .\my_script.py --flag --with=argument

I get a ConnectionRefusedErrors

debugpy\launcher/../..\debugpy\launcher\__init__.py", line 27, in connect
    sock.connect((host, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

So I figured I first need to start a server listening on port '53226' before running the command, right? I tried this:

python -m debugpy --listen 53226 --wait-for-client .\my_script.py --flag --with=argument

Now I start getting confused because I don't know if I should be invoking my script+arguments with debugpy or launcher

I retry the launcher command again:

python '<home_dir>\.vscode\extensions\ms-python.debugpy-2024.15.2024121701-win32-x64\bundled\libs\debugpy\launcher' '53226' '--' .\my_script.py --flag --with=argument

Now there's no ConnectionRefusedError, but the launcher program exits without showing any output, and my program is not run. I found out by reading the launcher code that it writes logs to a directory set by the DEBUGPY_LOG_DIR env variable. So I again attached some logs for the launcher program:

debugpy.launcher-15444.log

@rchiodo
Copy link
Contributor

rchiodo commented Jan 15, 2025

You can't actually debug with the launcher command, that's what VS code does. It opens the port that the launcher is talking to. I wanted you to try that to see if it threw any errors on the command line just from running debugpy, but maybe it's happening after the port is written to.

If you go back to the launch that you originally used, it has logToFile set. It should be writing out a bunch of logs here:

C:\Users\rchiodo\.vscode\extensions\ms-python.debugpy-2024.15.2024121701-win32-x64

Delete all the logs and try running it again. Then if you upload those logs here, it might have more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

3 participants