Issue #18874: Implement the PEP 454 (tracemalloc)

This commit is contained in:
Victor Stinner 2013-11-23 12:27:24 +01:00
parent 0fb6072fad
commit ed3b0bca3e
17 changed files with 4024 additions and 15 deletions

View file

@ -2154,3 +2154,22 @@ def patch(test_instance, object_to_patch, attr_name, new_value):
# actually override the attribute
setattr(object_to_patch, attr_name, new_value)
def run_in_subinterp(code):
"""
Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc
module is enabled.
"""
# Issue #10915, #15751: PyGILState_*() functions don't work with
# sub-interpreters, the tracemalloc module uses these functions internally
try:
import tracemalloc
except ImportError:
pass
else:
if tracemalloc.is_tracing():
raise unittest.SkipTest("run_in_subinterp() cannot be used "
"if tracemalloc module is tracing "
"memory allocations")
return _testcapi.run_in_subinterp(code)