Skip to content

Commit 7244cdc

Browse files
committed
gh-112087: Test fix for test_sched leak
1 parent 5dc8c84 commit 7244cdc

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Include/internal/pycore_gc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ extern PyObject *_PyGC_GetReferrers(PyInterpreterState *interp, PyObject *objs);
288288
extern void _PyGC_ClearAllFreeLists(PyInterpreterState *interp);
289289
extern void _Py_ScheduleGC(PyThreadState *tstate);
290290
extern void _Py_RunGC(PyThreadState *tstate);
291+
#ifdef Py_GIL_DISABLED
292+
extern void _PyGC_Clear_DelayedObjects(PyInterpreterState *interp);
293+
#endif
291294

292295
#ifdef __cplusplus
293296
}

Python/gc_free_threading.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
11541154
}
11551155
}
11561156

1157+
_PyGC_Clear_DelayedObjects(interp);
11571158
/* Update stats */
11581159
struct gc_generation_stats *stats = &gcstate->generation_stats[generation];
11591160
stats->collections++;
@@ -1758,4 +1759,16 @@ _PyGC_ClearAllFreeLists(PyInterpreterState *interp)
17581759
HEAD_UNLOCK(&_PyRuntime);
17591760
}
17601761

1762+
void
1763+
_PyGC_Clear_DelayedObjects(PyInterpreterState *interp)
1764+
{
1765+
HEAD_LOCK(&_PyRuntime);
1766+
PyThreadState *tstate = interp->threads.head;
1767+
while (tstate != NULL) {
1768+
_PyMem_ProcessDelayed(tstate);
1769+
tstate = (PyThreadState *)tstate->next;
1770+
}
1771+
HEAD_UNLOCK(&_PyRuntime);
1772+
}
1773+
17611774
#endif // Py_GIL_DISABLED

0 commit comments

Comments
 (0)