Repository navigation
Conversation
| # Make partial func pickable | ||
| def _reduce_partial(p): | ||
| return _rebuild_partial, (p.func, p.args, p.keywords or {}) | ||
| return p.__reduce__() |
There was a problem hiding this comment.
Does this mean that functools.partial instances are always picklable by default in all the Python version we support? If that's the case, we could just remove _reduce_partial / _rebuild_partial and register(functools.partial, _reduce_partial), no?
Keep the old reconstruction helper available for existing pickle artifacts.
I don't think we need this. Those custom pickling stuff are only meant to be privately used by loky internally for short lived commuication between a driver process and its worker process. Loky users should never keep long lived pickle artifacts on their hosts.
There was a problem hiding this comment.
Yes. Current master requires Python 3.11 or newer, whose standard partial reduction preserves this state. I removed the reducer, registration, reconstruction helper, and unused functools import. The serialization/wrapper checks pass on Python 3.11 and 3.14, and all 72 two-worker SciPy simulation results still match their serial references. I also removed the artifact-compatibility claim from the description.
Correction to the earlier version note: Python 3.10 was tested as extra compatibility, but is no longer supported by current master.
Use the standard partial reduction so callbacks retain their custom attributes, aliases and recursive keyword arguments when dispatched to workers. Keep the old reconstruction helper available for previously produced pickle artifacts. Cover both configured picklers and every supported pickle protocol.
f91bda9 to
1bdfc3a
Compare
Loky's partial reducer reconstructs the callable and arguments but loses its instance attributes. For example, sending a SciPy event callback created with
functools.partialto a worker drops.terminal, so integration continues past the requested stop.Remove the custom partial reducer and let the standard pickler preserve its dictionary, aliases and recursive state.
Validation: