Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing cannot find node inside Jupyter lab/notebooks #23

Closed
aroberge opened this issue Jul 24, 2021 · 6 comments
Closed

Executing cannot find node inside Jupyter lab/notebooks #23

aroberge opened this issue Jul 24, 2021 · 6 comments

Comments

@aroberge
Copy link

Using friendly, I found that excuting could not locate the correct location of a node causing a problem inside Jupyter notebooks (or Jupyter lab) but could do so with IPython. First, here's a screen capture showing the correct result using IPython, with some additional outputs from print statements inserted for this specific report.

image

Next, the same code run within a Jupyter notebook
image

Perhaps this is is caused by the new way that Jupyter runs code, using temporary files instead of using exec() on code.

With the "old" friendly-traceback (before it made use of stack_data), when Jupyter was not using temporary files, I see from screen captures on https://aroberge.github.io/friendly-traceback-docs/docs/html/jupyter.html that the location was correctly picked up.

@alexmojaki
Copy link
Owner

IPython needs special treatment, and executing uses the <ipython-input-*> filename pattern to determine if it's in IPython. See https://github.com/alexmojaki/executing/blob/master/executing/executing.py#L295-L296

The switch to files is annoying, I'll need to find a new way to reliably detect an IPython code object. This also affects snoop: https://github.com/alexmojaki/snoop/blob/49ce617297fcdd5efa46de70626a64997eee724d/snoop/tracer.py#L45

Thanks for letting me know about this.

@aroberge
Copy link
Author

So far, it seems that all files have names that contain ipykernel_. This is assigned in https://github.com/ipython/ipykernel/blob/7ed57cb4a03e719074c373029cf9f2e6dfd2c6de/ipykernel/compiler.py#L39

Future versions may include the code cell as information according to ipython/ipython#13043

@aroberge
Copy link
Author

The following code:

                            if (
                                code.co_filename.startswith("<ipython-input-")
                                or "Temp/ipykernel_" in code.co_filename
                            ) and code.co_name == "<module>":

seems to fix the problem.

image

@alexmojaki
Copy link
Owner

Released 0.8.0, please upgrade and confirm that this is fixed for you and that Python 3.10 also works.

@aroberge
Copy link
Author

Everything that I tested is working.

I only have automated tests for friendly-traceback (and not the friendly UI layer). Requiring friendly-traceback to use executing 0.8.0 did not change anything (as expected since it does not involve ipython): all tests pass, with Python 3.6 to 3.10 inclusively.

I normally only test ipython/jupyter with Python 3.9.

Doing a single test similar to the one above b = 4 + math.Pi:

  • iPython 7.25.0 (which uses the <ipython-...: works correctly (math.Pi identified as problematic node)
  • Jupyter lab (which uses temporary files): works correctly
  • Jupyter notebook (same as lab): works correctly.

With Python 3.10.0b4

  • ipython works correctly
  • jupyter notebook: works correctly
  • jupyter lab: seems to be stuck during installation; not tested. If I manage to get it install, I'll report the test result.
INFO: This is taking longer than usual. You might need to provide the dependency resolver
with stricter constraints to reduce runtime.
If you want to abort this run, you can press Ctrl + C to do so. ....

@alexmojaki
Copy link
Owner

Excellent! Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants