Skip to content

Isolate IPyKernel to a dedicated module / namespace#2

Closed
slippycheeze wants to merge 1 commit intobl-sdk:masterfrom
slippycheeze:patch-1
Closed

Isolate IPyKernel to a dedicated module / namespace#2
slippycheeze wants to merge 1 commit intobl-sdk:masterfrom
slippycheeze:patch-1

Conversation

@slippycheeze
Copy link
Copy Markdown

Create a dedicated module for IPyKernel to run code in. It defaults to using __main__, which exposes core parts of the SDK directoly to it.

Normally this wouldn't be so bad, except that various tools like the %reset magic can cause some trouble: that one resets the state of the namespace that IPyKernel is in to "default" by deleting almost everything.

Which, it turns out, includes various _... variables that are used by the SDK to do almost everything; after running it no mods worked, and in general the SDK was in a kind of broken state.

It might be nice to have access to __main__ easily, but not as nice as being protected from accidentally destroying everything. :)

Comment thread src/__main__.py Outdated

# Create a module and namespace for the code to run in: by default the kernel will attach
# to the caller, which leads to the `%reset` magic deleting a fair bit of the SDK...
ipy_user_module = type(sys)('ipython_user') # avoid importing `types` unnecessarily
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather just use the typos module, less magic

Create a dedicated module for IPyKernel to run code in.  It defaults to
using `__main__`, which exposes core parts of the SDK directoly to it.

Normally this wouldn't be so bad, except that various tools like the
`%reset` magic can cause some trouble: that one resets the state of the
namespace that IPyKernel is in to "default" by deleting
almost everything.

Which, it turns out, includes various `_...` variables that are used by
the SDK to do almost everything; after running it no mods worked, and in
general the SDK was in a kind of broken state.

It might be nice to have access to `__main__` easily, but not as nice as
being protected from accidentally destroying everything. :)
@slippycheeze
Copy link
Copy Markdown
Author

apparently I accidentally submitted a new pull request instead of updating this one, sorry.
#3

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

Successfully merging this pull request may close these issues.

2 participants