Repository navigation
Done
Description
| BPO | 30691 |
|---|---|
| Nosy | @Yhg1s, @birkenfeld, @rhettinger, @pitrou, @serhiy-storchaka |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = None
created_at = <Date 2017-06-17.18:54:10.235>
labels = ['library']
title = 'WeakSet is not pickleable'
updated_at = <Date 2017-06-18.06:09:54.301>
user = 'https://github.com/serhiy-storchaka'bugs.python.org fields:
activity = <Date 2017-06-18.06:09:54.301>
actor = 'rhettinger'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2017-06-17.18:54:10.235>
creator = 'serhiy.storchaka'
dependencies = []
files = []
hgrepos = []
issue_num = 30691
keywords = []
message_count = 4.0
messages = ['296243', '296256', '296262', '296264']
nosy_count = 5.0
nosy_names = ['twouters', 'georg.brandl', 'rhettinger', 'pitrou', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue30691'
versions = []Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
- StatusShow more project fieldsDone
Activity
webberfc commentedon Jun 19, 2023
Hello, I am using iPyParallel (or rather, attempting to) to support parallelizing a complex task. I have successfully used iPyParallel elsewhere in another project. Unfortunately, in this project, I have this error:
I have tried to identify what the object is so I can come up with a workaround (iPyParallel allows you to instantiate remotely so pickling is not required)... iPyParallel provides two workarounds to help with pickling, being Dill and CloudPickle. Dill complains:
TypeError: no default __reduce__ due to non-trivial __cinit__And CloudPickle is complaining about a thread, which I will have to look into, I thought this version was a single thread version up until the call to map_async.
Per the above request:
I am formally requesting this :) Thanks for considering! Meanwhile I'll try to ID the object and see if I can remove it...
hugovk commentedon Apr 26, 2025
How does PR #93732 look for this?
serhiy-storchaka commentedon Jul 17, 2026
My old #93732 added support for pickling WeakSet. I wrote also extended patch to support other types of weak containers. They work fine, but with caveat -- if user pickles weak references without strong references in the same pickle, they will became dead immediately after unpickling. Weak collections became empty.
#153818 solves this problem by making the pickler to trace weak references. If they are not backed by strong references, a PicklingError is raised at the end of pickling, so such mistake will not be left unnoticed. Only
weakref.refis supported natively in thepicklemodule, all other types are expressed in terms ofweakref.ref. This does not need introducing a new opcode and bumping protocol. But this is too large change for backporting. We should just raise explicit errors in old Python versions.The current version of PR uses private functions to reconstruct. I wonder if it is worth to add public alternative constructors like
WeakRef.fromrefs().gh-74876: Support pickling weak references and weak containers (#153818)
serhiy-storchaka commentedon Oct 21, 2026
I did not merge #153818 myself, because I was not completely satisfied by it. It depends on new private API, and the pickled data is not optimal and cannot be read in older versions. I have other idea and am going to try it.
gh-74876: Skip weakref pickling tests in test_xpickle for Python < 3.…
pythongh-74876: Pickle dead weak references as weakref.ref()
Revert "pythongh-74876: Pickle dead weak references as weakref.ref()"
pythongh-74876: Do not call reducer_override() for copyreg.Proxy in p…
pythongh-74876: Forbid subclassing copyreg.Proxy
pythongh-74876: Use an interned name to get copyreg.Proxy.obj in _pickle
gh-74876: Add copyreg.Proxy (GH-160219)
serhiy-storchaka commentedon Nov 27, 2026
copyreg.Proxyadded in #160219 allows to make weakref pickles more compact and unpickleable in old Python versions. It has a drawback -- during unpickling the dead weak references will look like weak references to an empty set. It is possible to fix it, bu then dead weak references will be unpickleable in old Python versions. The safe way is to add mechanism to create dead weak references in 3.16 and use it in pickle only when support for versions older than 3.16 is dropped.serhiy-storchaka commentedon Nov 28, 2026
Opened #162802 for broken copying.