File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,23 @@ struct ThreadState_DestroyNoGIL
96
96
// Python < 3.8 or >= 3.9
97
97
static int AddPendingCall (int (*func)(void *), void* arg)
98
98
{
99
+ // If the interpreter is in the middle of finalizing, we can't add a
100
+ // pending call. Trying to do so will end up in a SIGSEGV, as
101
+ // Py_AddPendingCall will not be able to get the interpreter and will
102
+ // try to dereference a NULL pointer. It's possible this can still
103
+ // segfault if we happen to get context switched, and maybe we should
104
+ // just always implement our own AddPendingCall, but I'd like to see if
105
+ // this works first
106
+ #if GREENLET_PY313
107
+ if (Py_IsFinalizing ()) {
108
+ #else
109
+ if (_Py_IsFinalizing ()) {
110
+ #endif
111
+ fprintf (stderr,
112
+ " greenlet: WARNING: Interpreter is finalizing. Ignoring "
113
+ " call to Py_AddPendingCall; \n " );
114
+ return 0 ;
115
+ }
99
116
return Py_AddPendingCall (func, arg);
100
117
}
101
118
#endif
You can’t perform that action at this time.
0 commit comments