Commit cb17094d authored by Benjamin Peterson's avatar Benjamin Peterson

disable the garbage collector while collecting traces, so that __del__s don't get caught

parent fc49f2a9
import gc
import pprint
import sys
import unittest
......@@ -354,9 +355,17 @@ protect_ident = ident(protect)
def capture_events(callable, p=None):
if p is None:
p = HookWatcher()
sys.setprofile(p.callback)
protect(callable, p)
sys.setprofile(None)
# Disable the garbage collector. This prevents __del__s from showing up in
# traces.
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]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment