-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Add IPython-specific session dump and load capability #103
base: master
Are you sure you want to change the base?
Conversation
byref_filter allows the caller to supply a function that determines whether a given name should be pickled byref. This permits white- or black-listing of imported items. byref_discard_missing specifies whether names marked by the byref_filter which cannot be found should be silently discarded. This allows dynamically-generated items to be specifically excluded.
These use the byref filtering mechanism to avoid pickling hidden items from the namespace. In Pylab or Matplotlib mode, this covers the implicit "from x import *". Items that cannot be found are silently discarded, which takes care of dynamically generated classes such as those from GObject which get thoughtlessly plunked into __main__ by the GTK backend. This also restores the hidden namespace after loading, ensuring that IPython's special handling of them in %who and so forth remains effective.
@abrasive: I barely looked at this, but as a start: can you not assume that the |
I didn't want to assume that all callers from IPython actually want to use IPython-specific dump and load wrappers. I'll integrate it into |
|
After giving this some more thought, and a better look, I have some updated comments. First, I don't believe |
@mmckerns I'm working on this issue with a different kind of solution. Code is growing. What do you think of splitting "session" related code to a submodule? Beyond its size, it also lays down in the way when navigating between imports and definitions and the |
I would think that the |
IPython imports a bunch of stuff into the user namespace in Pylab and Matplotlib modes (presumably amongst others). These implicit imports are hidden from the user in commands like
%who
.This patch is in two parts. The first modifies
dump_session
, adding a filtering capability to the new byref mechanism. A flag is also added to silently discard any byref object which cannot be found in imported modules.The second part adds IPython dump and load functions. The dumper marks any name in the IPython hidden namespace for byref pickling. This includes the implicit imports, as well as the hidden history variables. The history variables and any dynamically generated classes end up discarded by the byref mechanism. The hidden namespace list is saved in the dumped session.
The loader loads the session in the usual way, and then fixes up the hidden namespace again according to the information saved in the dump. This ensures that a subsequent dump and load will continue to work, as well as ensuring consistent behaviour of
%who
and friends.