cpython: 5abe85aefe29 (original) (raw)
Mercurial > cpython
changeset 83835:5abe85aefe29
Issue #17937: Try harder to collect cyclic garbage at shutdown. [#17937]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Sun, 19 May 2013 01:11:58 +0200 |
parents | e79df5d1f680 |
children | 1b5ef05d6ced |
files | Include/objimpl.h Misc/NEWS Modules/gcmodule.c Python/import.c |
diffstat | 4 files changed, 32 insertions(+), 6 deletions(-)[+] [-] Include/objimpl.h 4 Misc/NEWS 2 Modules/gcmodule.c 31 Python/import.c 1 |
line wrap: on
line diff
--- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -232,6 +232,10 @@ PyAPI_FUNC(PyVarObject ) _PyObject_NewV / C equivalent of gc.collect(). / PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void); +#ifndef Py_LIMITED_API +PyAPI_FUNC(Py_ssize_t) _PyGC_CollectNoFail(void); +#endif + / Test if a type has a GC head */ #define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ What's New in Python 3.4.0 Alpha 1? Core and Builtins ----------------- +- Issue #17937: Try harder to collect cyclic garbage at shutdown. +
--- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -853,7 +853,8 @@ get_time(void) /* This is the main function. Read this to understand how the
- collection process works. */ static Py_ssize_t -collect(int generation, Py_ssize_t *n_collected, Py_ssize_t *n_uncollectable) +collect(int generation, Py_ssize_t *n_collected, Py_ssize_t *n_uncollectable,
int nofail)[](#l3.9)
{ int i; Py_ssize_t m = 0; /* # objects collected */ @@ -1000,10 +1001,15 @@ collect(int generation, Py_ssize_t *n_co } if (PyErr_Occurred()) {
if (gc_str == NULL)[](#l3.17)
gc_str = PyUnicode_FromString("garbage collection");[](#l3.18)
PyErr_WriteUnraisable(gc_str);[](#l3.19)
Py_FatalError("unexpected exception during garbage collection");[](#l3.20)
if (nofail) {[](#l3.21)
PyErr_Clear();[](#l3.22)
}[](#l3.23)
else {[](#l3.24)
if (gc_str == NULL)[](#l3.25)
gc_str = PyUnicode_FromString("garbage collection");[](#l3.26)
PyErr_WriteUnraisable(gc_str);[](#l3.27)
Py_FatalError("unexpected exception during garbage collection");[](#l3.28)
} /* Update stats */ @@ -1062,7 +1068,7 @@ collect_with_callback(int generation) { Py_ssize_t result, collected, uncollectable; invoke_gc_callback("start", generation, 0, 0);}[](#l3.29)
- result = collect(generation, &collected, &uncollectable, 0); invoke_gc_callback("stop", generation, collected, uncollectable); return result; }
@@ -1544,6 +1550,19 @@ PyGC_Collect(void) return n; } +Py_ssize_t +_PyGC_CollectNoFail(void) +{
- /* This function should only be called on interpreter shutdown, and
therefore not recursively. */[](#l3.52)
- assert(!collecting);
- collecting = 1;
- n = collect(NUM_GENERATIONS - 1, NULL, NULL, 1);
- collecting = 0;
- return n;
+} void _PyGC_DumpShutdownStats(void)
--- a/Python/import.c +++ b/Python/import.c @@ -444,6 +444,7 @@ PyImport_Cleanup(void) /* Finally, clear and delete the modules directory */ PyDict_Clear(modules);