Calling PyEval_AddPendingCall while the interpreter is finalizing can lead to a segfault due to the implementation in CPython of PyEval_AddPendingCall. This is a somewhat hacky fix to just check if it's finalizing before we try and schedule the cleanup.
I say somewhat hacky, cause it's still possible to race between checking and actually calling PyEval_AddPendingCall and end up segfaulting, but in practice so far this fix has completely solved our segfaulting issues. Arguably the most ideal fix here would be to fix this call in CPython to not segfault when the interpreter is shutting down, and just terminate the thread like it now does with the locking API
Calling
PyEval_AddPendingCall
while the interpreter is finalizing can lead to a segfault due to the implementation in CPython ofPyEval_AddPendingCall
. This is a somewhat hacky fix to just check if it's finalizing before we try and schedule the cleanup.I say somewhat hacky, cause it's still possible to race between checking and actually calling
PyEval_AddPendingCall
and end up segfaulting, but in practice so far this fix has completely solved our segfaulting issues. Arguably the most ideal fix here would be to fix this call in CPython to not segfault when the interpreter is shutting down, and just terminate the thread like it now does with the locking APIFixes #411