Add news entry · python/cpython@52f3855 · GitHub
Skip to content

Commit 52f3855

Browse files
committed
Add news entry
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
1 parent e6b7b2c commit 52f3855

4 files changed

Lines changed: 28 additions & 7 deletions

File tree

Doc/whatsnew/3.12.rst

Lines changed: 7 additions & 0 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The Garbage Collector now runs only on the eval breaker mechanism of the
2+
Python bytecode evaluation loop instead on object allocations. The GC can
3+
also run when :c:func:`PyErr_CheckSignals` is called so C extensions that
4+
need to run for a long time without executing any Python code also have a
5+
chance to execute the GC periodically.

Modules/gcmodule.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,9 +2255,15 @@ PyObject_IS_GC(PyObject *obj)
22552255
void
22562256
_Py_ScheduleGC(PyInterpreterState *interp)
22572257
{
2258+
GCState *gcstate = &interp->gc;
2259+
if (gcstate->collecting == 1) {
2260+
return;
2261+
}
22582262
struct _ceval_state *ceval = &interp->ceval;
2259-
_Py_atomic_store_relaxed(&ceval->gc_scheduled, 1);
2260-
_Py_atomic_store_relaxed(&ceval->eval_breaker, 1);
2263+
if (!_Py_atomic_load_relaxed(&ceval->gc_scheduled)) {
2264+
_Py_atomic_store_relaxed(&ceval->gc_scheduled, 1);
2265+
_Py_atomic_store_relaxed(&ceval->eval_breaker, 1);
2266+
}
22612267
}
22622268

22632269
void

Python/ceval_gil.c

Lines changed: 8 additions & 5 deletions

0 commit comments

Comments
 (0)