-
-
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
dynamic classes not created in __main__ fail to pickle #56
Comments
Yeah, it one of the problems with the pickle approach. When it finds a class that's in a module, it assumes that is can be reloaded "on the other side". Dill adjusts this to completely pickle all "things" in def f():
global NewCls
cls = type('NewCls', (object,), dict())
NewCls = cls
print(dill.pickles(cls)) or change @mmckerns We could adjust |
These should be no different than named tuples, which "everyone knows" the instance needs to be named appropriately. The other part of this issue is having the instance creation done inside a class... and python misidentifies the namespace as being inside the file object -- this is one of the outstanding problems remaining for serialization, and solving it should solve a number of objects, I believe. I think it's safe to ignore the first part (naming) for now, as it is convention. |
Thanks. Trying out these workarounds, inserting the class in The second workaround, setting |
Feel free to post a minimal version of your program than reproduces the traceback you are seeing. For certain objects, it is currently possible to instruct |
|
Good point. @mattja: there are a few functions in |
Faking The further errors which resulted seem to be a separate issue so I've filed the details in #58. |
@mmckerns, in this case,
I have raised an issue containing more detail about this problem upstream. ( wbolster/qualname#2 ) |
@jakirkham: No, as I mentioned in the other thread, |
I think the behavior of |
That's fine. I just wanted to see if |
FYI, the above is the same as in the discussion from the other thread -- and, yes, I think the easier fix is to do so within |
|
Hi @wbolster, as you can see from this thread, this is an issue that has been around for a few years. Actually, it's been known (to at least me) for almost the entire life of I've known the "backport" solution (basically, what is done in
|
FWIW, it appears that |
@jakirkham: Thanks. I am very familiar with |
See interesting mapping done in: python/typeshed#24 |
@mmckerns Is it easier to fix this for Python 3 only? And if so, would it make sense at least for now? Maybe due to the wider Python 3 adoption and the fact that Python 2 will be discontinued "soon" (in less than 3 years), concentrating efforts in Python 3 is not a bad idea specially for the cases where Python 2 makes things more complicated (?). |
@Peque: yes, I believe the fix for 3.x is much easier. There have been a lot of changes since I dug into this last, and several older versions (<= 2.6, and <= 3.4) are basically unsupported by the python community... so it may be much easier of a task than previously. |
Need to set __module__ to __main__. uqfoundation/dill#56
Need to set __module__ to __main__. uqfoundation/dill#56
I would like to generate new classes programatically at runtime using
type()
, then serialize these (for use on other computers on a cluster). Is there a way to get dill to pickle these?Strangely, the classes seem to pickle ok if this is done by the
__main__
module, but not any other module. minimal test:classmaker.py:
consumer.py:
running these:
In the second case the pickling exception is:
Can't pickle <class 'classmaker.NewCls'>: it's not found as classmaker.NewCls
The text was updated successfully, but these errors were encountered: