mirror of
https://github.com/python/cpython.git
synced 2025-09-10 02:36:56 +00:00
disable the garbage collector while collecting traces, so that __del__s don't get caught
This commit is contained in:
parent
fc49f2a973
commit
cb17094dcd
1 changed files with 12 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import gc
|
||||||
import pprint
|
import pprint
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -354,9 +355,17 @@ protect_ident = ident(protect)
|
||||||
def capture_events(callable, p=None):
|
def capture_events(callable, p=None):
|
||||||
if p is None:
|
if p is None:
|
||||||
p = HookWatcher()
|
p = HookWatcher()
|
||||||
sys.setprofile(p.callback)
|
# Disable the garbage collector. This prevents __del__s from showing up in
|
||||||
protect(callable, p)
|
# traces.
|
||||||
sys.setprofile(None)
|
old_gc = gc.isenabled()
|
||||||
|
gc.disable()
|
||||||
|
try:
|
||||||
|
sys.setprofile(p.callback)
|
||||||
|
protect(callable, p)
|
||||||
|
sys.setprofile(None)
|
||||||
|
finally:
|
||||||
|
if old_gc:
|
||||||
|
gc.enable()
|
||||||
return p.get_events()[1:-1]
|
return p.get_events()[1:-1]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue