diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-04-12 22:07:58 -0700 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2018-04-15 23:39:49 -0700 |
commit | 3ff0c5c82b8abc4c94b1801a13f488778631f38a (patch) | |
tree | 8068b5c4c11e212559427965505f6f6983ed98cf /numpy/testing/_private/utils.py | |
parent | d21ec05eb006c072e4fd8c5fe1bd63619378aded (diff) | |
download | numpy-3ff0c5c82b8abc4c94b1801a13f488778631f38a.tar.gz |
BUG: Ensure the garbage is clear first in assert_no_gc_cycles
It's not always possible to guarantee this, so also adds a test to verify that we don't hang
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r-- | numpy/testing/_private/utils.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index 0c9fd644c..b0c0b0c48 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -2288,7 +2288,14 @@ def _assert_no_gc_cycles_context(name=None): gc.disable() gc_debug = gc.get_debug() try: - gc.collect() + for i in range(100): + if gc.collect() == 0: + break + else: + raise RuntimeError( + "Unable to fully collect garbage - perhaps a __del__ method is " + "creating more reference cycles?") + gc.set_debug(gc.DEBUG_SAVEALL) yield # gc.collect returns the number of unreachable objects in cycles that |