mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-39322: Add gc.is_finalized to check if an object has been finalised by the gc (GH-17989)
This commit is contained in:
parent
1d1b97ae64
commit
a2ec3f07f7
6 changed files with 75 additions and 1 deletions
|
@ -586,6 +586,24 @@ class GCTests(unittest.TestCase):
|
|||
self.assertFalse(gc.is_tracked(UserFloatSlots()))
|
||||
self.assertFalse(gc.is_tracked(UserIntSlots()))
|
||||
|
||||
def test_is_finalized(self):
|
||||
# Objects not tracked by the always gc return false
|
||||
self.assertFalse(gc.is_finalized(3))
|
||||
|
||||
storage = []
|
||||
class Lazarus:
|
||||
def __del__(self):
|
||||
storage.append(self)
|
||||
|
||||
lazarus = Lazarus()
|
||||
self.assertFalse(gc.is_finalized(lazarus))
|
||||
|
||||
del lazarus
|
||||
gc.collect()
|
||||
|
||||
lazarus = storage.pop()
|
||||
self.assertTrue(gc.is_finalized(lazarus))
|
||||
|
||||
def test_bug1055820b(self):
|
||||
# Corresponds to temp2b.py in the bug report.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue