]> granicus.if.org Git - python/commitdiff
Replace an overly optimistic assert() in _PyGC_CollectNoFail with a simple guard.
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 15 Aug 2013 18:15:15 +0000 (20:15 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 15 Aug 2013 18:15:15 +0000 (20:15 +0200)
Modules/gcmodule.c

index 02e0cb831ebd0172f448e9ed54f98a64b9468f15..a84d752ffa6c10720e4a3c764675871db85caaca 100644 (file)
@@ -1612,12 +1612,19 @@ _PyGC_CollectNoFail(void)
 {
     Py_ssize_t n;
 
-    /* This function should only be called on interpreter shutdown, and
-       therefore not recursively. */
-    assert(!collecting);
-    collecting = 1;
-    n = collect(NUM_GENERATIONS - 1, NULL, NULL, 1);
-    collecting = 0;
+    /* Ideally, this function is only called on interpreter shutdown,
+       and therefore not recursively.  Unfortunately, when there are daemon
+       threads, a daemon thread can start a cyclic garbage collection
+       during interpreter shutdown (and then never finish it).
+       See http://bugs.python.org/issue8713#msg195178 for an example.
+       */
+    if (collecting)
+        n = 0;
+    else {
+        collecting = 1;
+        n = collect(NUM_GENERATIONS - 1, NULL, NULL, 1);
+        collecting = 0;
+    }
     return n;
 }