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

Definition errors in lambda functions in embedded shells #5935

Closed
amelio-vazquez-reina opened this issue Jun 2, 2014 · 1 comment
Closed
Milestone

Comments

@amelio-vazquez-reina
Copy link

Say I define a shell to debug my code from IPython:

from IPython.terminal.embed import InteractiveShellEmbed
ipshell = InteractiveShellEmbed(config=cfg, banner1=banner_msg, exit_msg=exit_msg)

def ipsh():
   frame = inspect.currentframe().f_back
   msg = 'Stopped at {0.f_code.co_filename} at line {0.f_lineno}'.format(frame)
   ipshell(msg,stack_depth=2) # Go back one level!

I use it by leaving ipsh() anywhere in my code where I want to drop down into an IPython shell, i.e.

# code I want to debug/inspect
# ....
ipsh()
# code I want to debug/inspect
# ....

Once I am in this embedded shell, if I do the following:

ci = 50
f = lambda x: np.percentile(x, 100-ci)
f([20,40,60, 80, 100])

I get the error:
NameError: global nameciis not defined. This error doesn't happen if I run the snippet above from a regular IPython shell.

The above is with the latest stable version of IPython and Python (Python 2.7.x).

@amelio-vazquez-reina amelio-vazquez-reina changed the title Lambda functions in embedded shells Definition errors in lambda functions in embedded shells Jun 2, 2014
@takluyver
Copy link
Member

Thanks - I think this is the same as issue #136. There's more discussion there, but in short: it's a limitation of Python's execution model, but there may be a way we can work around it.

@minrk minrk added this to the no action milestone Oct 2, 2014
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

3 participants