Debugger spuriously stops on exceptions when using python interpreter from a virtualenv
See original GitHub issueEnvironment data
VS Code version: 1.19.1 Python Extension version: 0.9.1 Python Version: 2.7.14 OS and version: MacOs Sierra 10.12.6 Virtualenv version: 15.1.0
Actual behavior
With breaking on Uncaught Exceptions
option enabled, the debugger breaks inside re
module when using python interpreter coming from a virtual environment created by virtualenv. Hitting Continue
button has no end, it keeps breaking inside re
module, that happens to be indirectly imported in the first line of my code, so I can’t move forward with debugging without disabling the Uncaught Exceptions
option.
When using the same version of python interpreter, but installed globally, the debugger does not break inside re
module, it progresses through the code and breaks on first uncaught exception in my code.
Expected behavior
Debugger should behave the same way, no matter if I use virtualenv or system wide version of python.
Steps to reproduce:
- Create and activate virtualenv
mbp:~$ virtualenv code/python-venvs/testenv
New python executable in /Users/leszek/code/python-venvs/testenv/bin/python2.7
Also creating executable in /Users/leszek/code/python-venvs/testenv/bin/python
Installing setuptools, pip, wheel...done.
@mbp:~$ . code/python-venvs/testenv/bin/activate
(testenv) @mbp:~$ which python
/Users/leszek/code/python-venvs/testenv/bin/python
(testenv) @mbp:~$ python --version
Python 2.7.14
- Create sample code:
(testenv) @mbp:~$ echo '#!/Users/leszek/code/python-venvs/testenv/bin/python
import json
print var' > code/python-venvs/testenv/src/test.py
-
Open the
src
dir in VSCode, then open thetest.py
file, and click “Set as interpreter” above the first line of code to activate the interpreter provided by the virtualenv. -
Go to the debugger and click on the gear icon to populate
launch.json
with default settings. -
Select
Uncaught Exceptions
on the list of breakpoints -
Start the debugger with the
Python
configuration selected. -
The debugger breaks inside
sre_parse.py
file, instead it should break on the 5th line of code where I’m referencing undefined variablevar
. -
Keep clicking on Continue or just F5 on the keyboard, the debugger keeps breaking in the same place.
-
In VSCode, change the interpreter to the system wide one, in my case
/usr/local/bin/python2
, installed withbrew
:
(testenv) @mbp:~$ deactivate
@mbp:~$ which python2
/usr/local/bin/python2
@mbp:~$ /usr/local/bin/python2 --version
Python 2.7.14
- Restart the debugger, it doesn’t break inside
sre_parse.py
file, instead it breaks on the 5th line of my code.
Logs
Output from Python
output panel
Output from Console window
(Help->Developer Tools menu)
extensionHost.ts:290 [Extension Host] debugger listening on port 9334
extensionHost.ts:200 [Extension Host] debugger inspector at %cDebugger listening on port 9334.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9334/739de81d-5f39-40fa-926c-e43873c6758f
console.ts:123 [Extension Host] (node:91038) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
t.log @ console.ts:123
Settings
User settings:
{
"editor.rulers": [79],
"editor.fontSize": 11,
"terminal.integrated.fontSize": 12,
"editor.fontFamily": "Menlo, Monaco, 'Courier New', monospace",
// "python.venvPath": "/Users/leszek/code/python-venvs",
"python.linting.pylintPath": "/usr/local/bin/pylint",
"editor.minimap.enabled": true,
"window.zoomLevel": -1,
// "debug.allowBreakpointsEverywhere": true
}
Workspace settings:
{
"python.pythonPath": "/Users/leszek/code/python-venvs/testenv/bin/python"
}
launch.json
{
// 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",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
},
... skipping the rest here
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:7 (1 by maintainers)
Top GitHub Comments
I ran into this problem when trying to debug a custom Django management command running in python 3.6.5 under pipenv. Switching to the experimental debugger fixed it for me. Thank you!
Closing as the new release is out with the fix.