本文整理匯總了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