On my laptop I'm able to attach a VS Code debugger to a running python process, but on my desktop it always times out trying to connect.
- Laptop: Debian Stable (11) , python 3.9
- Desktop: Pop OS (Ubuntu 21.10), python 3.9.7
- I'm signed in to a Github account so the VS Code settings and extensions are synced.
I'm using this simple test file:
import time
while True:
print("hello, world")
time.sleep(1)
Debugging works fine when I start the script from (the default) launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
But when I use the following (also default) launch.json to attach to my already running process, I always end op getting a timeout message (on the desktop, the same script does work on the laptop):
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Attach using Process Id",
"type": "python",
"request": "attach",
"processId": "${command:pickProcess}",
"justMyCode": true
}
]
}
Enabling logToFile and comparing the logs between my laptop and desktop doesn't show any difference, apart from the timeout happening, and the port used (port 33191 on my laptop, 35205 on my desktop, both using 127.0.0.1 as the host). Putting this port in my config doesn't work, but I'm also not completely sure where this port number comes from and how the debugger injects itself into the process.
It seems the debugger can find the process (I can select it from the dropdown) but somehow isn't able to actually connect to it. Does anyone know what might be wrong, or have any suggestions to point me in the right direction? I've tried a bunch of suggestions from other posts, but they don't see to work (mostly outdated or for running the current file instead of attaching to an existing process).