| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -232,6 +232,10 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t); | |||
| 232 | 232 | /* C equivalent of gc.collect(). */ | |
| 233 | 233 | PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void); | |
| 234 | 234 | ||
| 235 | + #ifndef Py_LIMITED_API | ||
| 236 | + PyAPI_FUNC(Py_ssize_t) _PyGC_CollectNoFail(void); | ||
| 237 | + #endif | ||
| 238 | + | ||
| 235 | 239 | /* Test if a type has a GC head */ | |
| 236 | 240 | #define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC) | |
| 237 | 241 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,8 @@ What's New in Python 3.4.0 Alpha 1? | |||
| 10 | 10 | Core and Builtins | |
| 11 | 11 | ----------------- | |
| 12 | 12 | ||
| 13 | + - Issue #17937: Try harder to collect cyclic garbage at shutdown. | ||
| 14 | + | ||
| 13 | 15 | - Issue #12370: Prevent class bodies from interfering with the __class__ | |
| 14 | 16 | closure. | |
| 15 | 17 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -853,7 +853,8 @@ get_time(void) | |||
| 853 | 853 | /* This is the main function. Read this to understand how the | |
| 854 | 854 | * collection process works. */ | |
| 855 | 855 | static Py_ssize_t | |
| 856 | - collect(int generation, Py_ssize_t *n_collected, Py_ssize_t *n_uncollectable) | ||
| 856 | + collect(int generation, Py_ssize_t *n_collected, Py_ssize_t *n_uncollectable, | ||
| 857 | + int nofail) | ||
| 857 | 858 | { | |
| 858 | 859 | int i; | |
| 859 | 860 | Py_ssize_t m = 0; /* # objects collected */ | |
@@ -1000,10 +1001,15 @@ collect(int generation, Py_ssize_t *n_collected, Py_ssize_t *n_uncollectable) | |||
| 1000 | 1001 | } | |
| 1001 | 1002 | ||
| 1002 | 1003 | if (PyErr_Occurred()) { | |
| 1003 | - if (gc_str == NULL) | ||
| 1004 | - gc_str = PyUnicode_FromString("garbage collection"); | ||
| 1005 | - PyErr_WriteUnraisable(gc_str); | ||
| 1006 | - Py_FatalError("unexpected exception during garbage collection"); | ||
| 1004 | + if (nofail) { | ||
| 1005 | + PyErr_Clear(); | ||
| 1006 | + } | ||
| 1007 | + else { | ||
| 1008 | + if (gc_str == NULL) | ||
| 1009 | + gc_str = PyUnicode_FromString("garbage collection"); | ||
| 1010 | + PyErr_WriteUnraisable(gc_str); | ||
| 1011 | + Py_FatalError("unexpected exception during garbage collection"); | ||
| 1012 | + } | ||
| 1007 | 1013 | } | |
| 1008 | 1014 | ||
| 1009 | 1015 | /* Update stats */ | |
@@ -1062,7 +1068,7 @@ collect_with_callback(int generation) | |||
| 1062 | 1068 | { | |
| 1063 | 1069 | Py_ssize_t result, collected, uncollectable; | |
| 1064 | 1070 | invoke_gc_callback("start", generation, 0, 0); | |
| 1065 | - result = collect(generation, &collected, &uncollectable); | ||
| 1071 | + result = collect(generation, &collected, &uncollectable, 0); | ||
| 1066 | 1072 | invoke_gc_callback("stop", generation, collected, uncollectable); | |
| 1067 | 1073 | return result; | |
| 1068 | 1074 | } | |
@@ -1544,6 +1550,19 @@ PyGC_Collect(void) | |||
| 1544 | 1550 | return n; | |
| 1545 | 1551 | } | |
| 1546 | 1552 | ||
| 1553 | + Py_ssize_t | ||
| 1554 | + _PyGC_CollectNoFail(void) | ||
| 1555 | + { | ||
| 1556 | + Py_ssize_t n; | ||
| 1557 | + | ||
| 1558 | + /* This function should only be called on interpreter shutdown, and | ||
| 1559 | + therefore not recursively. */ | ||
| 1560 | + assert(!collecting); | ||
| 1561 | + collecting = 1; | ||
| 1562 | + n = collect(NUM_GENERATIONS - 1, NULL, NULL, 1); | ||
| 1563 | + collecting = 0; | ||
| 1564 | + return n; | ||
| 1565 | + } | ||
| 1547 | 1566 | ||
| 1548 | 1567 | void | |
| 1549 | 1568 | _PyGC_DumpShutdownStats(void) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -444,6 +444,7 @@ PyImport_Cleanup(void) | |||
| 444 | 444 | ||
| 445 | 445 | /* Finally, clear and delete the modules directory */ | |
| 446 | 446 | PyDict_Clear(modules); | |
| 447 | + _PyGC_CollectNoFail(); | ||
| 447 | 448 | interp->modules = NULL; | |
| 448 | 449 | Py_DECREF(modules); | |
| 449 | 450 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments