mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
[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:
parent
da602560a4
commit
f814675376
5 changed files with 50 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue