-
Notifications
You must be signed in to change notification settings - Fork 176
Dynamic class reset state on every deserialization #439
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
Comments
I forgot to mention that the |
Hi @sklam, As your reproducer shows, loading a pickle containing We could make it possible for users to turn off "class tracking", but knowing now the motivations and the benefits of class tracking, do you still think turning it off would be desirable for your use case? Do you have another "fix" in mind? |
@pierreglaser, the cloudpickle/cloudpickle/cloudpickle_fast.py Lines 402 to 403 in ef6fb90
_class_setstate is always called and it reset the state of Klass . It is an unexpected side-effect for cloudpickle.loads() to always reset the class state.
In Numba, I am attempting to patch the class tracking in cloudpickle to bypass the |
what When you try to reconcile a serialized version of For instance, if the I am not sure of what we should do upstream to support your use case. |
Consider the case in a distributed system and there are two threads running in a remote process, both of these threads are executing this: def worker(serialized_bytes):
Klass = cloudpickle.loads(serialize_bytes)
Klass.count += 1
do_something_else()
return Klass.count With random delay in starting the execution and in running The fact that a deserialization in a different thread can at a random time modify a state can lead to very hard to debug situations. |
hm.... the |
My feeling is that it won't help, since this feature allows only to add modules in which serialization by value will be enforced (and not the other way around), while your problem could maybe be solved by serializing
I agree, but the only possible alternative I'm seeing right now is to add some programmatic switching between the current behavior and a behavior prioritizing the child process. I don't have a definitive opinion on whether such a switch is worth adding, and would need to discuss with other core devs of cloudpickle/distributed frameworks to get a better idea of how much people would benefit from it. |
Reproducer:
Prints:
After each
loads(saved)
, the state inKlass
is being reset unexpectedly.This problem can appear like a tricky race condition in distributed, multi-threaded framework, such as Dask. See example https://gist.github.com/sklam/98e7c98ce909e76a3fa7904754db7bd9.
I created a patch for this in the vendored cloudpickle in Numba: numba/numba#7388. Please let me know if there will be problems with the way I am fixing it. If it is okay, I can submit the PR here.
The text was updated successfully, but these errors were encountered: