Open
Description
Instances of custom types can stash any references to other Python objects anywhere in their memory without telling the interpreter about it (they only should incref/decref). This makes the object graph opaque to Python runtime. Right now, it is solved by users provided tp_traverse
and tp_clear
.
- There is no control over what
tp_traverse
/tp_clear
can do. It can have bugs and miss some objects, it can do some extra work that it shouldn't blocking the caller for too long. - I think that the current contract is that
tp_traverse
/tp_clear
is called on a Python thread (that holds GIL). This means that GC cannot run concurrently with the application in a different thread, for example. - This prevents implementation of generational garbage collector or any collector that needs read or write barrier, because the runtime is not notified about reads/writes. Maybe the ref-counting scheme proposed for no-GIL could use this knowledge too.
The same applies to module state.
Related: #12