Is there any way to work around the limitations of WeakValueDictionary to allow it to hold weak references to built-in types like dict or list? Can something be done at the C level in an extension module? I really need a weakref container that can hold (nearly) any type of object.
From stackoverflow
-
According to the Python documentation you can create weak references to subclasses of
dictandlist... it's not a perfect solution, but if you're able to create a custom subclass ofdictand use that instead of a nativedict, it should be good enough. (I've never actually done this myself)David Zaslavsky : ah... well, I don't know of any way to create a fully general WeakValueDictionary that can hold anything at all. There are various tricks you can use in special cases, though - if you edit the question to specify what kinds of objects you need to have weak references to, it might help.
0 comments:
Post a Comment