Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fc49f2a commit cb17094Copy full SHA for cb17094
1 file changed
Lib/test/test_sys_setprofile.py
@@ -1,3 +1,4 @@
1
+import gc
2
import pprint
3
import sys
4
import unittest
@@ -354,9 +355,17 @@ def protect(f, p):
354
355
def capture_events(callable, p=None):
356
if p is None:
357
p = HookWatcher()
- sys.setprofile(p.callback)
358
- protect(callable, p)
359
- sys.setprofile(None)
+ # Disable the garbage collector. This prevents __del__s from showing up in
+ # traces.
360
+ old_gc = gc.isenabled()
361
+ gc.disable()
362
+ try:
363
+ sys.setprofile(p.callback)
364
+ protect(callable, p)
365
+ sys.setprofile(None)
366
+ finally:
367
+ if old_gc:
368
+ gc.enable()
369
return p.get_events()[1:-1]
370
371
0 commit comments