本文整理汇总了Python中sys.gettrace方法的典型用法代码示例。如果您正苦于以下问题:Python sys.gettrace方法的具体用法?Python sys.gettrace怎么用?Python sys.gettrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.gettrace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateSysTrace
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def updateSysTrace(self):
## Install or uninstall sys.settrace handler
if not self.ui.catchNextExceptionBtn.isChecked() and not self.ui.catchAllExceptionsBtn.isChecked():
if sys.gettrace() == self.systrace:
sys.settrace(None)
return
if self.ui.onlyUncaughtCheck.isChecked():
if sys.gettrace() == self.systrace:
sys.settrace(None)
else:
if sys.gettrace() is not None and sys.gettrace() != self.systrace:
self.ui.onlyUncaughtCheck.setChecked(False)
raise Exception("sys.settrace is in use; cannot monitor for caught exceptions.")
else:
sys.settrace(self.systrace)
示例2: restore_settrace
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def restore_settrace(monkeypatch):
"""(Re)store sys.gettrace after test run.
This is required to re-enable coverage tracking.
"""
assert sys.gettrace() is _orig_trace
orig_settrace = sys.settrace
# Wrap sys.settrace to restore original tracing function (coverage)
# with `sys.settrace(None)`.
def settrace(func):
if func is None:
orig_settrace(_orig_trace)
else:
orig_settrace(func)
monkeypatch.setattr("sys.settrace", settrace)
yield
newtrace = sys.gettrace()
if newtrace is not _orig_trace:
sys.settrace(_orig_trace)
assert newtrace is None
示例3: no_tracing
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def no_tracing(func):
"""Decorator to temporarily turn off tracing for the duration of a test."""
if not hasattr(sys, 'gettrace'):
return func
else:
def wrapper(*args, **kwargs):
original_trace = sys.gettrace()
try:
sys.settrace(None)
return func(*args, **kwargs)
finally:
sys.settrace(original_trace)
wrapper.__name__ = func.__name__
return wrapper
# Return True if opcode code appears in the pickle, else False.
示例4: run_with_trace
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def run_with_trace(config, script, **kwargs):
"""Same as run, but use the trace-inputlocator functionality to capture InputLocator calls"""
from cea.tests.trace_inputlocator import create_trace_function, update_trace_data, meta_to_yaml
if "multiprocessing" in kwargs:
# we can only trace single processes
kwargs["multiprocessing"] = False
# stuff needed for trace-inputlocator
script_start = datetime.datetime.now()
results_set = set()
orig_trace = sys.gettrace()
sys.settrace(create_trace_function(results_set))
run(config, script, **kwargs) # <------------------------------ this is where we run the script!
sys.settrace(orig_trace)
# update the trace data
trace_data = set()
update_trace_data(config, cea.inputlocator.InputLocator(config.scenario), results_set, script,
script_start, trace_data)
meta_to_yaml(config, trace_data, config.trace_inputlocator.meta_output_file)
示例5: main
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def main(config):
# force single-threaded execution, see settrace docs for why
config.multiprocessing = False
locator = cea.inputlocator.InputLocator(config.scenario)
trace_data = set() # set used for graphviz output -> {(direction, script, locator_method, path, file)}
for script_name in config.trace_inputlocator.scripts:
script_func = getattr(cea.api, script_name.replace('-', '_'))
script_start = datetime.now()
results_set = set() # {(locator_method, filename)}
orig_trace = sys.gettrace()
sys.settrace(create_trace_function(results_set))
script_func(config) # <------------------------------ this is where we run the script!
sys.settrace(orig_trace)
update_trace_data(config, locator, results_set, script_name,
script_start, trace_data)
print(trace_data)
scripts = sorted(set([td[1] for td in trace_data]))
config.restricted_to = None
meta_to_yaml(config, trace_data, config.trace_inputlocator.meta_output_file)
print('Trace Complete')
示例6: disable
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def disable(self, mode='soft'):
"""
Stops tracing.
"""
try:
if mode == 'soft':
self.clear_all_breaks()
self.set_continue()
# Remove this instance so that new ones may be created.
self.__class__._instance = None
elif mode == 'hard':
sys.exit(1)
else:
raise ValueError("mode must be 'hard' or 'soft'")
finally:
self.restore_output_streams()
if self.log_handler:
self.log_handler.pop_application()
self.cmd_manager.stop()
if sys.gettrace() is self.trace_dispatch:
sys.settrace(None)
示例7: testInteractionWithTraceFunc
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def testInteractionWithTraceFunc(self):
import sys
def tracer(a,b,c):
return tracer
def adaptgetter(name, klass, getter):
kind, des = getter
if kind == 1: # AV happens when stepping from this line to next
if des == "":
des = "_%s__%s" % (klass.__name__, name)
return lambda obj: getattr(obj, des)
class TestClass:
pass
self.addCleanup(sys.settrace, sys.gettrace())
sys.settrace(tracer)
adaptgetter("foo", TestClass, (1, ""))
sys.settrace(None)
self.assertRaises(TypeError, sys.settrace)
示例8: test_recursionlimit_recovery
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def test_recursionlimit_recovery(self):
if hasattr(sys, 'gettrace') and sys.gettrace():
self.skipTest('fatal error if run with a trace function')
oldlimit = sys.getrecursionlimit()
def f():
f()
try:
for depth in (10, 25, 50, 75, 100, 250, 1000):
try:
sys.setrecursionlimit(depth)
except RecursionError:
# Issue #25274: The recursion limit is too low at the
# current recursion depth
continue
# Issue #5392: test stack overflow after hitting recursion
# limit twice
self.assertRaises(RecursionError, f)
self.assertRaises(RecursionError, f)
finally:
sys.setrecursionlimit(oldlimit)
示例9: is_debugging
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def is_debugging():
"""Detect if a debugging session is in progress.
This looks at both pytest's builtin pdb support as well as
externally installed debuggers using some heuristics.
This is done by checking if either of the following conditions is
true:
1. Examines the trace function to see if the module it originates
from is in KNOWN_DEBUGGING_MODULES.
2. Check is SUPPRESS_TIMEOUT is set to True.
"""
global SUPPRESS_TIMEOUT, KNOWN_DEBUGGING_MODULES
if SUPPRESS_TIMEOUT:
return True
trace_func = sys.gettrace()
if trace_func and inspect.getmodule(trace_func):
for name in KNOWN_DEBUGGING_MODULES:
if name in inspect.getmodule(trace_func):
return True
return False
示例10: test_recursionlimit_recovery
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def test_recursionlimit_recovery(self):
if hasattr(sys, 'gettrace') and sys.gettrace():
self.skipTest('fatal error if run with a trace function')
# NOTE: this test is slightly fragile in that it depends on the current
# recursion count when executing the test being low enough so as to
# trigger the recursion recovery detection in the _Py_MakeEndRecCheck
# macro (see ceval.h).
oldlimit = sys.getrecursionlimit()
def f():
f()
try:
for i in (50, 1000):
# Issue #5392: stack overflow after hitting recursion limit twice
sys.setrecursionlimit(i)
self.assertRaises(RuntimeError, f)
self.assertRaises(RuntimeError, f)
finally:
sys.setrecursionlimit(oldlimit)
示例11: get_sys_gettrace
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def get_sys_gettrace(self):
return sys.gettrace()
示例12: no_tracing
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def no_tracing(func):
"""Decorator to temporarily turn off tracing for the duration of a test."""
if not hasattr(sys, 'gettrace'):
return func
else:
@functools.wraps(func)
def wrapper(*args, **kwargs):
original_trace = sys.gettrace()
try:
sys.settrace(None)
return func(*args, **kwargs)
finally:
sys.settrace(original_trace)
return wrapper
示例13: __call__
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def __call__(self, *args, **kw):
"""Profile a singe call to the function."""
self.ncalls += 1
old_trace = sys.gettrace()
try:
return self.profiler.runcall(self.fn, args, kw)
finally: # pragma: nocover
sys.settrace(old_trace)
示例14: __init__
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def __init__(self):
self.original_trace_function = sys.gettrace()
self.prev_lineno = None
self.prev_timestamp = None
self.prev_path = None
self.lines = deque()
self._execution_count = defaultdict(lambda: defaultdict(int))
self._heatmap = defaultdict(lambda: defaultdict(float))
示例15: __init__
# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def __init__(self, target_modules):
self._events_list = deque()
self._original_trace_function = sys.gettrace()
self._process = psutil.Process(os.getpid())
self._resulting_events = []
self.mem_overhead = None
self.target_modules = target_modules