Closed guileryu01 closed 2 years ago
Does it work if you use debugpy.listen()
etc instead?
Yes. I tried adding
import debugpy
debugpy.listen(("localhost", 5678))
debugpy.wait_for_client()
in the code, and launching the debugger with the following config:
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
}
}
This way, the debugger was able to attach to a Jupyter python session.
I'm not entirely sure what goes wrong here, but I'm also not quite surprised because Jupyter has its own integrated debugging facilities, so our and their might be clashing here. Attach-by-PID is particularly fragile in that regard due to all the hacks necessary to hijack an already-running interpreter.
Have you considered using the built-in Jupyter debugging support in VSCode? Aside from taking care of all this for you, it will also do things such as setting breakpoints in code cells and stepping through them, which doesn't work well in a regular attach debug session.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks#_debug-a-jupyter-notebook
Thanks for the suggestion. Yes both "Debug cell" or "Run by line" work, which is also what I'm using. However I didn't find an equivalent function for Jupyter integrative window, and attaching by process ID is the only way that I found that worked until recently.
Interactive window should have its own 'Debug Cell' (you may be not seeing it in your python script if you're not putting the cell markers # %%)
https://code.visualstudio.com/docs/python/jupyter-support-py#_jupyter-code-cells
I see, although it would still be nice if I could leave the modules alone and do all the testing in the python interactive window. Is it possible to trigger this debug function from python interactive directly, e.g. same as what Ctrl+Shift+Alt+Enter does in an actual Jupyter Notebook?
There's no way to 'debug' the current selection, but you can debug the entire python file with 'Jupyter: Debug current file in Interactive Window'.
Debug current cell requires the cell markers be available, but the Debug current file will just load the entire python file as a single cell and let you step over it one line at a time.
There's no way to 'debug' the current selection, but you can debug the entire python file with 'Jupyter: Debug current file in Interactive Window'.
Debug current cell requires the cell markers be available, but the Debug current file will just load the entire python file as a single cell and let you step over it one line at a time.
Any reason that the Debug Current File in Interactive Window
or Jupyter: Run Current File in Python Interactive Window
disappears as an option in Jupyter notebook?
Any reason that the Debug Current File in Interactive Window or Jupyter: Run Current File in Python Interactive Window disappears as an option in Jupyter notebook?
Notebooks have their own way to debug cells. You can debug from the UI on the notebook itself.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks#_debug-a-jupyter-notebook
Environment data
Actual behavior
Timed out whiling waiting for debugger to attach to running Jupyter interactive window or Jupyter notebook.
Attaching to a regular python shell works for me.
Expected behavior
Be able to attach to these running processes.
Steps to reproduce:
Launch a python Jupyter interactive window and choose Python: Attach using Process Id.
I remember this used to work for me before recent updates to vs code. I've also tried setting logToFile to true in my launch.json, which generates the following log in debugpy.adapter: