[IPython-user] can't pickle interactively defined function

Fernando Perez fperez.net@gmail....
Mon Oct 27 14:38:08 CDT 2008


Howdy,

On Mon, Oct 27, 2008 at 11:04 AM, Robert Kern <robert.kern@gmail.com> wrote:
> Robin wrote:
>> On Mon, Oct 27, 2008 at 5:19 PM, Robert Kern <robert.kern@gmail.com> wrote
>>> We're not putting things defined in the namespace in the __main__ module. I'm
>>> not sure what the best approach should be, here. There might be multiple
>>> namespaces floating around. Presumably, they shouldn't all be linked to __main__.
>>
>> Thanks for looking into it...
>>
>> I'm a bit out of my depth with this stuff - from Googling the __main__
>> module in Ipython is actually a FakeModule - whether or not this is
>> designed to contain interactively designed stuff I'm not sure.
>
> Given this part of the docstring:
>
>     This is not meant to replace a module, but to allow inserting a fake
>     module in sys.modules so that systems which rely on run-time module
>     importing (like shelve and pickle) work correctly in interactive IPython
>     sessions.
>
> it looks like it was meant for this purpose. Devs, has something changed or did
> pickling functions defined interactively never work? I notice that I get the
> same error when trying to pickle an instance of a class defined interactively:

I think that it never worked, but I'm not 100% sure.  That's the
problem with old code we had no tests for (my fault), we have no
protection against regressions.

The FakeModule stuff arose from trying to fight some weird bug reports
I got from users of pickle and shelve very early in ipython's
development (years ago) and unfortunately I didn't have at the time
the discipline to build a test suite for that stuff, so we'd properly
have documented what exactly it was meant to address.

I do remember it being subtle and confusing, which may be part of why
the docstring itself isn't too informative (despite the sad lack of
tests, I did generally write fairly thorough docstrings and comments,
so this case was also partly due to the problem itself being poorly
understood by me).

Cheers,

f


More information about the IPython-user mailing list