summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_gc.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_gc.py')
-rw-r--r--Lib/test/test_gc.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index bb7df1f..cc2b4fa 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -1065,6 +1065,29 @@ class GCTests(unittest.TestCase):
self.assertEqual(len(gc.get_referents(untracked_capsule)), 0)
gc.get_referents(tracked_capsule)
+ @cpython_only
+ def test_get_objects_during_gc(self):
+ # gh-125859: Calling gc.get_objects() or gc.get_referrers() during a
+ # collection should not crash.
+ test = self
+ collected = False
+
+ class GetObjectsOnDel:
+ def __del__(self):
+ nonlocal collected
+ collected = True
+ objs = gc.get_objects()
+ # NB: can't use "in" here because some objects override __eq__
+ for obj in objs:
+ test.assertTrue(obj is not self)
+ test.assertEqual(gc.get_referrers(self), [])
+
+ obj = GetObjectsOnDel()
+ obj.cycle = obj
+ del obj
+
+ gc.collect()
+ self.assertTrue(collected)
class IncrementalGCTests(unittest.TestCase):