Isolate IPyKernel to a dedicated module / namespace#2
Closed
slippycheeze wants to merge 1 commit intobl-sdk:masterfrom
Closed
Isolate IPyKernel to a dedicated module / namespace#2slippycheeze wants to merge 1 commit intobl-sdk:masterfrom
slippycheeze wants to merge 1 commit intobl-sdk:masterfrom
Conversation
apple1417
requested changes
Mar 4, 2026
|
|
||
| # 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 |
Contributor
There was a problem hiding this comment.
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. :)
Author
|
apparently I accidentally submitted a new pull request instead of updating this one, sorry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
%resetmagic 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. :)