[IPython-user] Feature suggestion: %remember
Fernando.Perez at colorado.edu
Thu Dec 29 02:42:02 CST 2005
Ville Vainio wrote:
> On 12/8/05, Fernando Perez <Fernando.Perez at colorado.edu> wrote:
>>The problem is that pickle is notoriously finicky, and there are many
>>innocuous-looking things in python which can NOT be pickled, so this function
>>can fail at any time.
> It's easy to test this by trying to pickle an object when you do
> %remember - if it doesn't pickle correctly, it's not written to the
> data structure. This would still break if the user remembered
> something in a deleted module, but see below.
>>failed to write. But I'm not sure how useful such an unreliable tool would
>>be, and with ipython I always resist putting in the core something which is
>>too easy to break in everyday use.
> It would only break other remembered variables (instead of them &
> bookmarks) if I/someone hacked the persistence system in
> iplib.post_config_initialization() and iplib.atexit_operations() to
> use shelve instead of pickle/unpickle (probably a good idea anyway).
> I see it as a rather risk-free operation with high potential for
> enhancing the "seamless" user experience, a'la ancient systems where
> all data was persisted... wasn't the "abc" language, an inspiration
> for python, like this?
>>So if you write it for your own purposes, by all means send it and I'll put it
>>up on the wiki. But until you can convince me that we can have this in the
>>core and be _reliable_, I'm afraid I'll balk at it.
> I believe I can convince you :-). Think of this as a generalization of
> the bookmark functionality...
>>ps - implementation tips: use shelve, atexit, and in your magic, store the
>>list of names to be rememberd as a hidden var in the user namespace:
>>self.shell.user_ns['__magic_remember'] = ....
>>With these, the actual implementation should be very, very easy (if not robust
>>due to the problems listed above).
> There is already the "persist" member variable in iplib, I think I'll use it.
> I think I'd also "remember" (i.e. shelve) the variable immediately on
> the execution of %remember. I'd also enhance the bookmark
> functionality to commit the created bookmark immediately, to avoid the
> case where there are multiple ipython instances of ipython and the
> last to close is the only one to get the bookmarks saved.
> I believe this is good stuff and won't burn anyone, even people who
> push the envelope and are willing to abuse the system. :-)
OK, go for it. I was thinking of a %store which would remember the _name_ of
the variable, and track it down as it changed, storing upon exit. That is
nearly impossible to make reliable.
But the more limited form you propose (%store foo tries to pickle foo right
away, and if it fails, immediately alerts you), I think it can be useful.
Work on a patch and send it my way.
Please note that I've made MAJOR changes over the last few days, so you really
need to update SVN before you send me anything on this front. I'll try to put
out a .16 release candidate for the first week of January.
More information about the IPython-user