You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dill breaks cloudpickle > 1.3.0 on inner functions with closure #393
Hi, thanks for the report, I can reproduce locally. This is due to a recent refactoring in cloudpickle that decreased the priority of some cloudpickle reducers, including the one for cell objects. The consequence is that cloudpickle can in some case give the priority to other registered reducers. In this precise case, importing dill triggers a global side effect which add a high-priority cell reducer that is not compatible with cloudpickle's way of reducing cells.
The main problem is that importing dill triggers a global side effect. Ideally, this should not happen - so I suggest you open a bug in dill. Feel free to tag me in it in case the maintainers need more detail.
You can just turn off the injection (temporarily, if you like) with dill.extend(False). This provides a toggle for the injection of dill types into the pickle registry, so you can turn it back on with dill.extend(True). It's not a dill bug, it's that the two packages make different choices, some of which are incompatible -- and with the registry injection from dill, this actually enables both serializers to work together often enough. You might also want to use dill.settings['recurse'] = True either globally, or on a per-dump basis, to tell dill to use serialization choices that are closer to the choices that cloudpickle also makes.
The issue now is that the workaround is very difficult to implement in practice, since it would require to be very careful import import orders and how other libs load dill and cloudpickle. Could cloudpickle do something like this?
dill interaction: See analysis in this comment. This btw. can also be fixed by installing pickle5 since cloudpickle prefers using it as a base implementation and dill doesn't seem to have a side-effect on it.
pydantic issue: See example in this comment. Even if dill is not involved, the pydantic issue still remains, at least under python 3.6.
Activity
pierreglaser commentedon Aug 25, 2020
Hi, thanks for the report, I can reproduce locally. This is due to a recent refactoring in
cloudpicklethat decreased the priority of somecloudpicklereducers, including the one forcellobjects. The consequence is thatcloudpicklecan in some case give the priority to other registered reducers. In this precise case, importingdilltriggers a global side effect which add a high-prioritycellreducer that is not compatible withcloudpickle's way of reducing cells.The main problem is that importing
dilltriggers a global side effect. Ideally, this should not happen - so I suggest you open a bug indill. Feel free to tag me in it in case the maintainers need more detail.mmckerns commentedon Aug 27, 2020
You can just turn off the injection (temporarily, if you like) with
dill.extend(False). This provides a toggle for the injection ofdilltypes into the pickle registry, so you can turn it back on withdill.extend(True). It's not adillbug, it's that the two packages make different choices, some of which are incompatible -- and with the registry injection fromdill, this actually enables both serializers to work together often enough. You might also want to usedill.settings['recurse'] = Trueeither globally, or on a per-dump basis, to telldillto use serialization choices that are closer to the choices thatcloudpicklealso makes.davidsmf commentedon Sep 1, 2020
Thanks, this helps. I think I'm now back to a bug in cloudpickle with custom metaclasses.
this works with
cloudpickle==1.3.0, but not withcloudpickle==1.5.0. Is this a bug? Am I doing something wrong?I'm on python 3.6. It works on python 3.8.
marco-neumann-by commentedon Sep 18, 2020
So this works:
This however does NOT:
The issue now is that the workaround is very difficult to implement in practice, since it would require to be very careful import import orders and how other libs load dill and cloudpickle. Could cloudpickle do something like this?
marco-neumann-by commentedon Dec 3, 2020
Please note that there are two issues here:
pickle5sincecloudpickleprefers using it as a base implementation anddilldoesn't seem to have a side-effect on it.dillis not involved, thepydanticissue still remains, at least under python 3.6.marco-neumann-by commentedon Dec 3, 2020
For pydantic, the issue is the interaction between:
https://github.com/samuelcolvin/pydantic/blob/de0657e4a5495de9378db9fe15a17334c2b0fae5/pydantic/main.py#L865-L868
and:
cloudpickle/cloudpickle/cloudpickle.py
Line 460 in cdc704d
pierreglaser commentedon Dec 3, 2020
I'm wondering: are the two issues related? If not, can you please open a separate issue for the
pydanticinteraction?