summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-10-17 01:29:11 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-10-17 01:29:11 (GMT)
commitcb17094dcde6b450cece3fd54a1314cba5aff067 (patch)
tree623c4bf3793140be3090b0992a8ae4f79c567568 /Lib
parentfc49f2a973ffbd7d679cf82ca28637a96354cbdb (diff)
downloadcpython-cb17094dcde6b450cece3fd54a1314cba5aff067.zip
cpython-cb17094dcde6b450cece3fd54a1314cba5aff067.tar.gz
cpython-cb17094dcde6b450cece3fd54a1314cba5aff067.tar.bz2
disable the garbage collector while collecting traces, so that __del__s don't get caught
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_sys_setprofile.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/test/test_sys_setprofile.py b/Lib/test/test_sys_setprofile.py
index f9bf9ab..1532226 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]