From: Benjamin Peterson Date: Sun, 17 Oct 2010 01:29:11 +0000 (+0000) Subject: disable the garbage collector while collecting traces, so that __del__s don't get... X-Git-Tag: v3.2a4~511 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cb17094dcde6b450cece3fd54a1314cba5aff067;p=thirdparty%2FPython%2Fcpython.git disable the garbage collector while collecting traces, so that __del__s don't get caught --- diff --git a/Lib/test/test_sys_setprofile.py b/Lib/test/test_sys_setprofile.py index f9bf9ab22191..1532226f77e1 100644 --- a/Lib/test/test_sys_setprofile.py +++ b/Lib/test/test_sys_setprofile.py @@ -1,3 +1,4 @@ +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]