On 2013-08-19, Volker Braun <vbrau...@gmail.com
> Obviously you are deleting something in the remove callback, causing=20
> another remove callback to be called.
Meanwhile we made progress (or even found a solution).
One indeed obtained the "recursion depth exceeded ... ignored", when one
has a MonoDict M and objects a1, a2, a3,..., putting M[a1]=a2,
M[a2]=a3,..., keeping a reference to a1. And if one then does "del a1",
then the callback for a1 deletes a2, which immediately triggers a
callback that deletes a3, and so on.
The point is: The next callback is invoked *before* the previous
callback has returned. So, the callback for a1 should better keep a2 alive
until it has returned. I tested that it is not enough to keep it alive
by having a local variable inside of the callback pointing to it. So,
the solution that I suggest at #15069: Let the callback *return* a2. In
that way, a2 will be alive until the return is completed, and
immediately afterwards it will be deleted, causing the next callback.
Hence, the callbacks are executed one after the other, without nesting.
Note that Python's weakref.WeakKeyDictionary has the same problems with
nested callbacks. Hence, if you think you can give #15069 a positive
review (hint-hint), then Sage's MonoDict and TripleDict will have yet
another advantage over WeakKeyDicitonary :)