The 2018 answer by Lucas Rath worked for me, but:
- it only worked after I made sure my program could run in the first place (my program didn't run due to an uncaught exception, so I couldn't debug until I found & fixed that exception)
- Lucas' answer is similar to the the advice here, which I think might be better solution if you prefer to see a terminal open...
That is, you can continue to use launch.json "console": "integratedTerminal"
, but change your default terminal profile to the Command Prompt:
(My suggestion is better if you prefer to see Command Prompt output in the opened terminal. But my suggestion is worse if you don't care about Command Prompt output, and/or you don't want to change your default terminal for whatever reason)
More context
I deleted details (see history of my edits), but in case they help other people find this question & answer, note if you use "Git Bash" as your integrated terminal and you try to debug you may see this error in the terminal after the "Timed out" dialog appears:
More details:
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "c:\Users\username\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher\__main__.py", line 91, in <module>
main()
File "c:\Users\username\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher\__main__.py", line 47, in main
launcher.connect(host, port)
File "c:\Users\username\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\launcher\__init__.py", line 34, in connect
raise e
File "c:\Users\username\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\launcher\__init__.py", line 30, in connect
sock.connect((host, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
Another answer works
This other answer also works for me, without changing my terminal (i.e. still using Git Bash as my default terminal and using "console": "integratedTerminal"
in my launch.json
I used a higher value (180) for the DEBUGPY_PROCESS_SPAWN_TIMEOUT
environment variable, and I checked echo $DEBUGPY_PROCESS_SPAWN_TIMEOUT
actually printed the value.
My "Git Bash" is slow to open in general (even without VS Code). Try opening your Git Bash after a fresh restart of your windows machine; if it takes longer than 15 seconds (default value for DEBUGPY_PROCESS_SPAWN_TIMEOUT
), that explains the timeout! (Whereas opening my Command Prompt goes very quickly, which explains why using Command Prompt instead can work!)