#13394: Write a WeakValueDictionary with safer key removal
-------------------------------------+-------------------------------------
Reporter: nbruin | Owner: rlm
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-5.13
Component: memleak | Resolution:
Keywords: | Merged in:
Authors: Simon King | Reviewers:
Report Upstream: None of the above | Work issues:
- read trac for reasoning. | Commit:
Branch: | c3dba989f73c1eec0a66cf72ae203132fe33b5da
u/SimonKing/ticket/13394 | Stopgaps:
Dependencies: |
-------------------------------------+-------------------------------------
Comment (by SimonKing):
Hi Nils,
Replying to [comment:19 nbruin]:
> See [http://bugs.python.org/issue417795]. I'm not convinced by its
reasoning. Certainly in sage we're already depending on cyclic GC left and
right, so I don't see the issue (we wouldn't dream of subclassing
WeakValueDictionary with a `__del__` method). It's also a very old fix,
probably stemming from a time that people were still suspicious about the
cyclic GC.
Yes, I expected it would be something like this.
> If this stuff would get merged in Python, it would probably need the
weakref, but I don't think it needs it in Sage.
OK.
> For iterator stuff: in Python3 this is fixed. See
[http://hg.python.org/cpython/file/default/Lib/weakref.py] for starters
(and [http://hg.python.org/cpython/file/default/Lib/_weakrefset.py] for
`_IteratorGuard`). You probably just want to backport that stuff wholesale
into your own module.
OK.
Since I believe that this shouldn't be exposed to the user interface, I
think I'll try to base it on cdef attributes. Similarly, it might make
sense to create the callback function during initialisation of the
dictionary (with self provided as a closure, not by a weakref in a default
argument) and store it in a cdef attribute of the dictionary. In that way,
it won't be exposed to the user. Ideally, `dir(WeakValueDictionary)`
should return the same names as `dir(dict)`.
--
Ticket URL: <http://trac.sagemath.org/ticket/13394#comment:20>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.