vscode-jupyter: Intermittent ECONNREFUSED when starting debugger in Python Interactive window
Bug: Notebook Editor, Interactive Window, Editor cells
Steps to cause the bug to occur
- conda create -n test python=3.8 jupyter
- Launch VS Code, create a main.py file, and select the “test” Conda environment as the Python interpreter
- Create two cells in main.py
# %%
def foo():
a = 2 + 2
return a
# %%
b = foo()
b
- Click “Run Cell” in the first cell
- Click “Debug Cell” in the second cell --> Will give ECONNREFUSED error
- Exit from ECONNREFUSED error (click Cancel)
- Click “Restart IPython kernel” in the Python Interactive Window
- Repeat steps 4 and 5 --> Will work
- Can detach/reattach debugger, and debug/run cells as often as desired
- Restart kernel (repeat step 7), and then repeat steps 4 and 5, and will get ECONNREFUSED error again
- This time restarting the IPython kernel won’t fix it, need to restart VS Code, and repeat steps 4-8 (i.e. it will fail the first time after restarting VS Code, but restarting the kernel will fix it)
Actual behavior
ECONNREFUSED errors requiring restart of IPython kernel (the first time), and both VS Code and the IPython kernel (subsequent times)
Looking at the output of lsof -nP -iTCP | grep LISTEN
, there are several python processes listening on ports, but none of them are on the port the debugger is trying to connect to (causing the ECONNREFUSED error). There appear to be python processes listening on the two subsequent ports, though. For example the debugger will show an ECONNREFUSED error on port 61910, but lsof -nP iTCP | grep LISTEN
will show python processes listening on both ports 61911 and 61912. When it does work, I see processes listening on the desired port, plus the two additional ones, for example the Out variable will indicate port 62050, and there will be python processes listening on ports 62050, 62051, and 62055. (not 62052).
Note, the non-interactive (standard Python) debugger works fine every time. This is just when trying to perform “Debug Cell” or “Debug Current File in Python Interactive Window”
Expected behavior
Debugger attaches every time when working in Interactive Python mode.
Your Jupyter and/or Python environment
Please provide as much info as you readily know
- Jupyter server running: Local
- Extension version: 2020.8.101144
- VS Code version: 1.48.0
- Setting python.jediEnabled: false (disabled via python.dataScience.runStartupCommands, see below)
- Setting python.languageServer: None
- Python and/or Anaconda version: Python 3.8.5, Conda 4.8.4
- OS: Windows | Mac OS X 10.15.6
- Virtual environment: conda
- settings.json:
"python.dataScience.askForKernelRestart": false,
"python.dataScience.runStartupCommands": [
"%config IPCompleter.use_jedi = False",
"import warnings",
"warnings.simplefilter(action='default')"
],
"python.experiments.optInto": ["DeprecatePythonPath - experiment"],
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["--line-length", "120"],
"terminal.integrated.inheritEnv": true,
"python.dataScience.interactiveWindowMode": "perFile"
Python Output
(attached)
Microsoft Data Science for VS Code Engineering Team: @rchiodo, @IanMatthewHuff, @DavidKutu, @DonJayamanne, @greazer, @joyceerhl
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (10 by maintainers)
It can absolutely be solved, we just didn’t have a specific reason to prioritize this higher before.
Just upvoted https://github.com/microsoft/vscode-python/issues/11970. I wish I could upvote more than once, as this is a big one for us. 😃 Should we keep this issue open while we wait for that one to be resolved? Thanks for your help tracking down what what happening, and thanks for your work on the extension!