if (PyObject_CallFinalizerFromDealloc(self) < 0) {
return; // resurrected
}
+ // Untrack the object before unregistering the task, since the
+ // latter can cause a stop-the-world pause, after which another
+ // thread might call the GC and reach the object while it is
+ // semi-deallocated but still tracked
+ PyObject_GC_UnTrack(self);
+
// unregister the task after finalization so that
// if the task gets resurrected, it remains registered
unregister_task((TaskObj *)self);
PyTypeObject *tp = Py_TYPE(self);
- PyObject_GC_UnTrack(self);
-
PyObject_ClearWeakRefs(self);
(void)TaskObj_clear(self);