Following the recent discussion about restrictions to tp_traverse handlers.
In #131264 (comment) @colesbury noted that
PyThreadState_GetUnchecked() != NULL seems like a sufficient way to decide if it's safe to call into the interpreter.
I have previously observed that PyThreadState_GetUnchecked will return non-null when inside a tp_traverse handler. Should it be changed to return NULL so that @colesbury 's statement remains valid inside tp_traverse handlers too?
If no, I have ways I can workaround in PyO3. But I worry about edge cases like a signal handler being hit inside of tp_traverse, maybe in that case code will need to check whether it is attached to the interpreter (with PyThreadStateGetUnchecked?) and then if not, safely fail to attach until the traverse has finished.
Following the recent discussion about restrictions to
tp_traversehandlers.In #131264 (comment) @colesbury noted that
I have previously observed that
PyThreadState_GetUncheckedwill return non-null when inside atp_traversehandler. Should it be changed to returnNULLso that @colesbury 's statement remains valid insidetp_traversehandlers too?If no, I have ways I can workaround in PyO3. But I worry about edge cases like a signal handler being hit inside of
tp_traverse, maybe in that case code will need to check whether it is attached to the interpreter (withPyThreadStateGetUnchecked?) and then if not, safely fail to attach until the traverse has finished.