5

I'm following Microsoft's guide Getting Started with Python in VS Code, but can only run in debug mode once -- the following run will always hit a time out issue.

This is the hello.py

msg = "Hello World"
print(msg)

This is the launch.json, which basically only added "stopOnEntry": true so will stop at the first line of code during debugging:

{
 // Use IntelliSense to learn about possible attributes.
 // Hover to view descriptions of existing attributes.
 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
 "version": "0.2.0",
 "configurations": [ 
 {
 "name": "Python: Current File",
 "type": "python",
 "request": "launch",
 "program": "${file}",
 "console": "integratedTerminal",
 "stopOnEntry": true
 }
 ]
}

So my first round of debugging works, the terminal inside Visual Studio Code shows:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Playground\vscode\py\ms>c:/Playground/vscode/py/ms/env/Scripts/activate.bat
(env) C:\Playground\vscode\py\ms>cd c:\Playground\vscode\py\ms && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && c:\Playground\vscode\py\ms\env\Scripts\python.exe c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 58792 c:\Playground\vscode\py\ms\hello.py "
Hello World

However, if I click debug button again, it jammed, showing an error dialogue:

[Window Title]
Visual Studio Code
[Content]
timeout
[Open launch.json] [Cancel]

, and Terminal inside vscode shows:

(env) C:\Playground\vscode\py\ms>cd c:\Playground\vscode\py\ms && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && c:\Playground\vscode\py\ms\env\Scripts\python.exe c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 58798 c:\Playground\vscode\py\ms\hello.py "
E00001.107: Exception escaped from start_client
 Traceback (most recent call last):
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\log.py", line 110, in g
 return f(*args, **kwargs)
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\pydevd_hooks.py", line 74, in start_client
 sock, start_session = daemon.start_client((host, port))
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\daemon.py", line 217, in start_client
 connect(client, addr)
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\socket.py", line 197, in connect
 sock.connect(addr)
 ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
Traceback (most recent call last):
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\ptvsd_launcher.py", line 43, in <module>
 main(ptvsdArgs)
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\__main__.py", line 434, in main
 run()
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\__main__.py", line 296, in run_file
 setup_connection()
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\__main__.py", line 287, in setup_connection
 daemon = ptvsd._remote.attach(addr)
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\_remote.py", line 91, in attach
 patch_multiprocessing=ptvsd.options.multiprocess)
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\_vendored\pydevd\pydevd.py", line 2017, in settrace
 wait_for_ready_to_run,
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\_vendored\pydevd\pydevd.py", line 2068, in _locked_settrace
 debugger.connect(host, port) # Note: connect can raise error.
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\_vendored\pydevd\pydevd.py", line 914, in connect
 s = start_client(host, port)
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\pydevd_hooks.py", line 132, in <lambda>
 _start_client = (lambda h, p: start_client(daemon, h, p))
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\log.py", line 110, in g
 return f(*args, **kwargs)
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\pydevd_hooks.py", line 74, in start_client
 sock, start_session = daemon.start_client((host, port))
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\daemon.py", line 217, in start_client
 connect(client, addr)
 File "c:\Users\drlren\.vscode\extensions\ms-python.python-2019年5月18日875\pythonFiles\lib\python\ptvsd\socket.py", line 197, in connect
 sock.connect(addr)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

What happened? and how can I sort it out?

asked Jun 20, 2019 at 3:41

2 Answers 2

5

I resolved this issue changing the terminal from "bash" to "Command prompt" (cmd).

answered Nov 10, 2019 at 12:11
Sign up to request clarification or add additional context in comments.

2 Comments

And how to do that?
When you open a terminal console, at the top right you will see a drop-down list with the different terminal options you have available.
1

I had the same timeout problem on VS Code with a freshly installed Python Extension by Microsoft. What I did was installing the plugin and then immediately try to debug a file, which ended in a ConnectionRefusedError.

To resolve, I simply restarted VS Code.

answered Nov 17, 2021 at 21:22

1 Comment

Please define the python plugin used since there are several options available.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.