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
hashlib.new cannot be pickled when passed to ProcessPoolExecutor as a hash factory #162716
Passing hashlib.new to a ProcessPoolExecutor worker as a hash factory raises PicklingError before the worker runs. Passing hashlib.sha256 to the same worker succeeds. The failure can be reproduced without starting a worker or creating a hash object:
The first assertion passes. The second fails in pickle.dumps on CPython 3.16.0a2:
_pickle.PicklingError: Can't pickle <function __hash_new at ...>: it's not found as hashlib.__hash_new
Lib/hashlib.py exports either __hash_new or __py_new as new, then deletes both private names. The exported function retains its private __qualname__, so pickle tries to look it up under a name the module has deleted. With _hashlib unavailable, the same example fails looking up hashlib.__py_new.
To check whether the public name works across backends, I set hashlib.new.__qualname__ = "new" in the sending process. An unmodified receiving process then restored its own hashlib.new. This passed in both directions between the OpenSSL and built-in implementations with pickle protocols 0 through 5.
Related issue #55980 concerns serializing a hash object after construction. This reproducer only serializes the module-level constructor.
Reproduced on Linux with CPython 3.11.18, 3.12.14, 3.13.5, 3.14.10, 3.15.2, 3.16.0a2, and main at 3b30937.
CPython versions tested on:
3.11, 3.12, 3.13, 3.14, 3.15, 3.16, CPython main branch
Activity
sirosen commentedon Nov 27, 2026
Can you explain why it is important to be able to pickle
hashlib.new?Not all objects support pickling.
I'm inclined to close this as a wontfix, unless there is some real motivation for it.