question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Step into only works during the first run when debugging through interactive

See original GitHub issue

Applies To

  • Notebooks (.ipynb files)
  • Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

The contents of test.py:

# %%
import numpy

print(numpy.__version__)

Also:

  • I set up a breakpoint at import numpy in test.py above.
  • I have "jupyter.debugJustMyCode": false in the settings.
  • I run VS Code under Windows. I connect to a remote, which has Ubuntu. (Local Extension: Remote - SSH v0.80.0)

First run:

  1. I click “Debug Cell”. The debugger pauses in a finally-clause in interactiveshell.py (probably an uncaught exception)
  2. I press F5 (Continue) to step out of interactiveshell.py. The debugger points at import numpy.
  3. I press F11 (Step in) to step into the import statement. As expected, the editor opens __init__.py of the module, and I can trace the execution.
  4. I stop the debugger

Subsequent runs:

  1. [as above]
  2. [as above]
  3. I press F11 (Step in) to step into the import statement. The unexpected happens: instead of stepping into __init__.py, I find the debugger at interactiveshell.py:3457: exec(code_obj, self.user_global_ns, self.user_ns)

After I click “Restart” in the interactive window, the expected behaviour restores for the following run, after which the bug comes back.

If when stepped in __init.py__ I set a breakpoint there, then this breakpoint works in first runs, but is ignored in subsequent runs.

VS Code Version

Version: 1.67.0-insider (system setup) Commit: a3d53f76790d8c88f835afe85225ff6442703409 Date: 2022-04-07T05:15:43.863Z Electron: 17.3.1 Chromium: 98.0.4758.141 Node.js: 16.13.0 V8: 9.8.177.13-electron.0 OS: Windows_NT x64 10.0.19042

Jupyter Extension Version

v1.0.6

Jupyter logs

https://gist.github.com/avm19/201a983fb65ebbf543a2641b0030776d

Coding Language and Runtime Version

Python 3.7.7

Language Extension Version (if applicable)

v2022.5.10971003

Anaconda Version (if applicable)

conda 4.11.0

Running Jupyter locally or remotely?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rchiodocommented, Apr 8, 2022

The not stepping into __init__.py sounds more like the design of how packages work. Once a package is loaded into a python process it doesn’t run __init__.py again.

This has some more information: https://docs.python.org/3/tutorial/modules.html#tut-packages

So in this case if you debug a normal python file, you’re starting a python process every time. You’d expect to be able to debug __init__.py each time.

If you debug from a kernel, it should only step into that file once, the first time the package is loaded into the kernel.

0reactions
avm19commented, Apr 8, 2022

My bad, thanks for explaining!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Navigate through code by using the Visual Studio debugger
While debugging, open the Call Stack window by selecting Debug > Windows > Call Stack. In the Call Stack window, right-click a function...
Read more >
Debugging Python in VSCode - 03 - Step Into and Step Out
This video is part of my comprehensive 48+ hour Python course available on Udemy:https://www.udemy.com/course/learn- to -code-with-python/?
Read more >
Debugging in Visual Studio Code
To run or debug a simple app in VS Code, select Run and Debug on the Debug start view or press F5 and...
Read more >
22 Debugging | Advanced R - Hadley Wickham
22.4.1 browser() commands · Next, n : executes the next step in the function. · Step into, or s : works like next,...
Read more >
In Pycharm How to load code to interactive debugger?
To execute the selection in a debugger console, you first need to have the debugger running. You need to run a script using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found