-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
FrozenInstanceError with pickle in Spark #79
Comments
Well because 16.0 didn't have frozen classes? :) Pickle seems to use |
Actually, my code doesn't use frozen. attr.Attribute uses frozen, and that's what breaks. This exact code is working fine with 16.0.0. |
Oh drat! |
So it turns out Spark's pickle does fancy things to pickle things pickle can't pickle. (say that fast). Basic pickle couldn't serialize an
And it works with Spark. Basic test:
This fails with It would be a good idea to add this to |
(Commenting on the commit) Ha, that's very clever. It cuts down attr.Attribute instantiation time by ~45%. However, it slows down access on the Attribute fields, so for example asdict is slower by ~12%. It's an interesting tradeoff, but I'd always trade class definition time (~once per process) for runtime operations like asdict that get called n times. I wouldn't know about picking attr.Attribute, but pickling instances of non-frozen attr classes in general seems to work fine. (Frozen, not so much, yeah.) Does PySpark require you to pickle classes, as well as instances? |
PySpark is more aggressive about what it pickles so it can support lambda and inline classes. |
FWIW, I could live with adding PySpark to the test suite to prevent future regressions. |
Just to clarify, my initial comment was to do with changing the Attribute class to have the What are the exact combinations of parameters that trigger this? |
PR done. I added a test to pickle all the classes defined in the dark magic test. It seems to work fine with frozen classes without It works fine with Spark, or rather, my previously working Spark code works with this patch. |
Hm, really? On Python 3.5, only both slots=True and frozen=True fails. https://gist.github.com/Tinche/33b702c6a1c3e4093be95953720cd80c |
I test with 2.7. Any |
Hm, can confirm, on 2.7 cases B and C fail. On 3.5 only C fails. |
Slots seems to be supported by Pickle in Python 3.5 without |
Using Apache Spark, with attr 16.1.0, I get this error.
Unfortunately, I can't reproduce it with simple code, for some reason. Using IPython, I managed to track it down to rebuilding
Attributes
class:Spark uses a custom pickler in order to support local function and classes, but still uses the standard unpickler.
This was not an issue with 16.0.0, so sticking to that for now.
The text was updated successfully, but these errors were encountered: