File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -311,16 +311,21 @@ atexit_unregister(PyObject *module, PyObject *func)
311311 if (cb == NULL ) {
312312 continue ;
313313 }
314-
315- // We need to hold our own reference to this
316- // in case another thread is trying to unregister as well.
317314 PyObject * to_compare = cb -> func ;
315+
316+ // Unlock for fear of a custom __eq__ causing re-entrancy
318317 _PyAtExit_UNLOCK (state );
319318 int eq = PyObject_RichCompareBool (to_compare , func , Py_EQ );
320319 if (eq < 0 ) {
321320 return NULL ;
322321 }
323322 _PyAtExit_LOCK (state );
323+ if (state -> callbacks [i ] == NULL )
324+ {
325+ // Edge case: another thread might have
326+ // unregistered the function while we released the lock.
327+ continue ;
328+ }
324329 if (eq ) {
325330 atexit_delete_cb (state , i );
326331 }
You can’t perform that action at this time.
0 commit comments