Don't run garbage collection on interpreter exit if it was explicitly disabled
by the user.
This commit is contained in:
parent
9e3ef52a35
commit
fef7e94fa1
|
@ -224,11 +224,12 @@ PyAPI_FUNC(void) PyObject_SetArenaAllocator(PyObjectArenaAllocator *allocator);
|
||||||
* ==========================
|
* ==========================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* C equivalent of gc.collect(). */
|
/* C equivalent of gc.collect() which ignores the state of gc.enabled. */
|
||||||
PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void);
|
PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void);
|
||||||
|
|
||||||
#ifndef Py_LIMITED_API
|
#ifndef Py_LIMITED_API
|
||||||
PyAPI_FUNC(Py_ssize_t) _PyGC_CollectNoFail(void);
|
PyAPI_FUNC(Py_ssize_t) _PyGC_CollectNoFail(void);
|
||||||
|
PyAPI_FUNC(Py_ssize_t) _PyGC_CollectIfEnabled(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Test if a type has a GC head */
|
/* Test if a type has a GC head */
|
||||||
|
|
|
@ -1596,6 +1596,15 @@ PyGC_Collect(void)
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Py_ssize_t
|
||||||
|
_PyGC_CollectIfEnabled(void)
|
||||||
|
{
|
||||||
|
if (!enabled)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return PyGC_Collect();
|
||||||
|
}
|
||||||
|
|
||||||
Py_ssize_t
|
Py_ssize_t
|
||||||
_PyGC_CollectNoFail(void)
|
_PyGC_CollectNoFail(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -600,12 +600,12 @@ Py_FinalizeEx(void)
|
||||||
* XXX but I'm unclear on exactly how that one happens. In any case,
|
* XXX but I'm unclear on exactly how that one happens. In any case,
|
||||||
* XXX I haven't seen a real-life report of either of these.
|
* XXX I haven't seen a real-life report of either of these.
|
||||||
*/
|
*/
|
||||||
PyGC_Collect();
|
_PyGC_CollectIfEnabled();
|
||||||
#ifdef COUNT_ALLOCS
|
#ifdef COUNT_ALLOCS
|
||||||
/* With COUNT_ALLOCS, it helps to run GC multiple times:
|
/* With COUNT_ALLOCS, it helps to run GC multiple times:
|
||||||
each collection might release some types from the type
|
each collection might release some types from the type
|
||||||
list, so they become garbage. */
|
list, so they become garbage. */
|
||||||
while (PyGC_Collect() > 0)
|
while (_PyGC_CollectIfEnabled() > 0)
|
||||||
/* nothing */;
|
/* nothing */;
|
||||||
#endif
|
#endif
|
||||||
/* Destroy all modules */
|
/* Destroy all modules */
|
||||||
|
@ -632,7 +632,7 @@ Py_FinalizeEx(void)
|
||||||
* XXX Python code getting called.
|
* XXX Python code getting called.
|
||||||
*/
|
*/
|
||||||
#if 0
|
#if 0
|
||||||
PyGC_Collect();
|
_PyGC_CollectIfEnabled();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Disable tracemalloc after all Python objects have been destroyed,
|
/* Disable tracemalloc after all Python objects have been destroyed,
|
||||||
|
|
Loading…
Reference in New Issue