From e72cedfa052e016c8d3c87002a193f2f5d7bfc7d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Fri, 23 Feb 2018 23:22:42 -0600 Subject: [PATCH] Force GC before MinRecursionLimit exits --- pytools/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pytools/__init__.py b/pytools/__init__.py index a9c58ce..25881d5 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -1939,6 +1939,18 @@ class MinRecursionLimit(object): sys.setrecursionlimit(new_limit) def __exit__(self, exc_type, exc_val, exc_tb): + # Deep recursion can produce deeply nested data structures + # (or long chains of to-be gc'd generators) that cannot be + # undergo garbage collection with a lower recursion limit. + # + # Force a garbage collection while the recursion limit is + # still high to avoid this situation. + # + # See https://gitlab.tiker.net/inducer/sumpy/issues/31 for + # context. + import gc + gc.collect() + sys.setrecursionlimit(self.prev_recursion_limit) # }}} -- GitLab