-1

Following issue: I'm working on the remote server to which I connect with VSCode. I want to develop my python code (mostly statistical analysis and usual matplotlib visualization, nothing too fancy). I used to do it by running my python script in a debug mode by simply pushing 'Debug Python File' button, but currently it results in opening a new terminal on my remote. Now, I was told that we are supposed to launch a interactive job first (qsub ...) before working on the statistical analysis. The problem is, if I launch a job through qsub it opens me an interactive terminal in my current terminal, but if I am trying to push 'Debug Python File', it VSCode opens a new terminal, which is not in my interactive job mode.

Following the VSCode python debugging help page intructions, I tried running python -m debugpy --listen 0.0.0.0:5678 ./myscript.py from my current terminal with interactive job. It worked in theory but it didn't recognize any of my breakpoints in the script. Is there a different way to launch a python debugger in the current terminal in VSCode so the breakpoints are recognized? Should something be specified in launch.json? Any help is highly appreciated!

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 25 '23 at 20:48

1 Answers1

0

The Debug function provided by the Python extension will use a dedicated terminal.

If you wish to debug in a terminal that is currently open, I suggest using pdb.

You can do it according to the following steps:

  1. add import pdb to your codes.
  2. You can add pdb.set_trace() to set a breakpoint in your python file.
  3. In your current terminal, navigate to the directory where your Python file is located.
  4. Run the Python file by using command python -m pdb your_file.py.

But I still recommend that you use the debugging function provided by the VSCode Python extension, which you can configure in more detail in the launch.json file.

You can refer to document for more details about Debugging in VSCode.

MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13