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

IPython.embed_kernel() fails to capture scope in newly defined functions when run in top-level exception handler #11011

Open
ebanner opened this issue Feb 15, 2018 · 2 comments

Comments

@ebanner
Copy link

ebanner commented Feb 15, 2018

Consider the following program.

def catch(exctype, value, tb):
    import IPython
    IPython.embed_kernel()

import sys
sys.excepthook = catch

raise Exception

I am unable to define subsequent functions which reference variables defined outside the body in a jupyter console --existing session. For example

In [1]: xxx = 5

In [2]: def foo():
      :     xxx
      : 

In [3]: foo()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
~/foo.py in <module>()
----> 1 foo()

~/foo.py in foo()
      1 def foo():
----> 2     xxx
      3 

NameError: name 'xxx' is not defined

Is this a bug or a limitation of IPython.embed_kernel() when it is put as a top-level exception handler? For instance if I put IPython.embed_kernel() anywhere else I am able to define functions which reference variables defined outside of the body.

My IPython version is 6.2.1 and my version of jupyter console is 5.2.0.

@takluyver
Copy link
Member

This is a known limitation - see #62.

@ebanner
Copy link
Author

ebanner commented Feb 26, 2018

Thanks for the link! Lots of discussion about this and it looks like there is at least one workaround. I'll try it.

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