[Python-checkins] r85590 - python/branches/py3k/Lib/test/test_sys_setprofile.py

benjamin.peterson python-checkins at python.org
Sun Oct 17 03:29:11 CEST 2010


Author: benjamin.peterson
Date: Sun Oct 17 03:29:11 2010
New Revision: 85590

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

Modified:
   python/branches/py3k/Lib/test/test_sys_setprofile.py

Modified: python/branches/py3k/Lib/test/test_sys_setprofile.py
==============================================================================
--- python/branches/py3k/Lib/test/test_sys_setprofile.py	(original)
+++ python/branches/py3k/Lib/test/test_sys_setprofile.py	Sun Oct 17 03:29:11 2010
@@ -1,3 +1,4 @@
+import gc
 import pprint
 import sys
 import unittest
@@ -354,9 +355,17 @@
 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]
 
 


More information about the Python-checkins mailing list