[3.9] bpo-43439: Add audit hooks for gc functions (GH-24794). (GH-24811)

(cherry picked from commit b4f9089d4a)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
Pablo Galindo 2021-03-10 08:50:29 +00:00 committed by GitHub
parent da602560a4
commit f814675376
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 0 deletions

View file

@ -323,6 +323,24 @@ def test_socket():
sock.close()
def test_gc():
import gc
def hook(event, args):
if event.startswith("gc."):
print(event, *args)
sys.addaudithook(hook)
gc.get_objects(generation=1)
x = object()
y = [x]
gc.get_referrers(x)
gc.get_referents(y)
if __name__ == "__main__":
from test.support import suppress_msvcrt_asserts