-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
cPickle works in standard interpreter, but not in IPython #29
Comments
[ LP comment 1 by: avdd, on 2009-07-16 03:48:57.797382+00:00 ] Has nothing to do with pickle, but the FakeModule that is registered as main: $ python
a$ ipython In [1]: import sys In [2]: sys.modules[name].foo = 1 In [3]: fooNameError Traceback (most recent call last) /home/avdd/ in () NameError: name 'foo' is not defined In [4]: |
[ LP comment 2 by: Matt Hickford, on 2009-07-18 19:36:43.821085+00:00 ] I have problem that neither pickle nor cPickle work in ipython (but work in python proper). In my case pickle.dump works but pickle. This is Jaunty, Python 2.6 My error: (I have a custom class inherited from list called Dictionary) |
[ LP comment 3 by: Ville M. Vainio, on 2009-07-18 20:11:20+00:00 ] On Sat, Jul 18, 2009 at 10:36 PM, Matt
I think you'll note that pickle works when the class of the pickleable Ville M. Vainio |
[ LP comment 4 by: reckoner, on 2009-07-19 23:50:39+00:00 ] If you get the class using the %run magic instead of importing, you DO Any guidance appreciated. thanks. On Sat, Jul 18, 2009 at 1:11 PM, Ville M. Vainiovivainio@gmail.com wrote:
|
[ LP comment 5 by: eteq, on 2009-12-17 01:34:20.367155+00:00 ] I've encountered this in the past - I always just define any class I want to pickle in a file and then reload the module as necessary instead of pickling outputs from run or interactively-defined objects. That seems safer anyway - otherwise if you restart the interpreter, the methods on the object are forgotten. It seems to work fine if you pickle from a file and then load that file with an interactively-defined or defined in "run" version, though. |
[ LP comment 6 by: Zak Stone, on 2009-12-17 03:02:24.672555+00:00 ] For me, a similar problem arises when I am simply unpickling dictionaries in ipython -- no custom classes involved. |
This means that interactively defined functions cannot be used with multiprocessing, as described in #86 |
The problem appears to be that the FakeModule used for In [1]: from IPython.core.fakemodule import init_fakemod_dict In [2]: ip = get_ipython() In [3]: fakemain = sys.modules['__main__'] In [4]: ip.register_post_execute(lambda : init_fakemod_dict(fakemain, ip.user_ns)) This manually syncs the |
Thanks for the hack, Min. This is a really important one to fix, though I'm reluctant to make it a blocker because it's hard work that may delay us for a while, and it's such an old bug that we've obviously managed to live with it. But I'd be thrilled to see a proper fix for this. |
@fperez do you know if there is a way for us to just have the FM.dict softlink to user_ns, rather than doing a one-time copy? I couldn't figure out a way in my relatively brief exploration of this, but it seems like that would resolve the whole problem. |
On Fri, Apr 8, 2011 at 9:49 AM, minrk
My concern would be the fact that this would couple a module (a global The FakeModule thing is something I wrote years ago, at the very |
Right, but it's specifically the I certainly don't know enough about what |
On Fri, Apr 8, 2011 at 10:46 AM, minrk
That's why I'm reluctant to make this one a blocker right now: it's Cheers, f |
The exact same issue causes #131. This should also get a "FakeModule" label, but I can't figure out how to add it myself (maybe only organization members can do that). |
On Sat, Apr 9, 2011 at 1:31 PM, dwf
Done, thanks! Unfortunately github only allows repo owners to set labels... |
I've had a go at this, if people want to test my pickle-interactive branch. See pull request #384 for more explanation. |
…and add test for pickling interactively defined objects. Closes ipythongh-29
added 'py' format, which is cleaner than PyWriter
…and add test for pickling interactively defined objects. Closes ipythongh-29
Clean up handling of global namespaces with the proper semantics. A global namespace should always be tied to a module: pickle accesses classes via the module in which they're defined. So I've changed the arguments for instantiating an InteractiveShell to include `user_module` in place of `user_global_ns`. The global namespace simply becomes a reference to `user_module.__dict__`. For instantiating InteractiveShell, there are four possibilities: * Neither `user_ns` nor `user_module` is given. A new (real) module is created named `__main__`, and its `__dict__` becomes the global and local namespace. This is what happens when starting IPython normally. * Only `user_module` is given. Its `__dict__` becomes the global and local namespace. * Both `user_ns` and `user_module` are given. `user_module.__dict__` is the global namespace, and `user_ns` is the local namespace. Note that we can't interactively define closures over variables in the local namespace (this seems to be a limitation of Python). * Only `user_ns` is given. It is treated as the global and local namespace, and a `DummyMod` object is created to refer to it. This is intended as a convenience, especially for the test suite. The recommended way to pass in a single global namespace is as a reference to the module. `embed()` digs out the locals and the module from the frame in which it's called. Closes ipythongh-29, closes ipythongh-693.
Original Launchpad bug 363115: https://bugs.launchpad.net/ipython/+bug/363115
Reported by: reckoner (reckoner).
For example in IPython:
However, using the standard Python interpreter:
The text was updated successfully, but these errors were encountered: