当前位置: 首页>>代码示例>>Python>>正文


Python sys.gettrace方法代码示例

本文整理汇总了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) 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:19,代码来源:Console.py

示例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 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:26,代码来源:conftest.py

示例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. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:pickletester.py

示例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) 
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:25,代码来源:workflow.py

示例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') 
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:27,代码来源:trace_inputlocator.py

示例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) 
开发者ID:quantopian,项目名称:qdb,代码行数:23,代码来源:tracer.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_scope.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_sys.py

示例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 
开发者ID:pytest-dev,项目名称:pytest-timeout,代码行数:24,代码来源:pytest_timeout.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:21,代码来源:test_sys.py

示例11: get_sys_gettrace

# 需要导入模块: import sys [as 别名]
# 或者: from sys import gettrace [as 别名]
def get_sys_gettrace(self):
        return sys.gettrace() 
开发者ID:war-and-code,项目名称:jawfish,代码行数:4,代码来源:regrtest.py

示例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 
开发者ID:war-and-code,项目名称:jawfish,代码行数:16,代码来源:support.py

示例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) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:10,代码来源:profilehooks.py

示例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)) 
开发者ID:nvdv,项目名称:vprof,代码行数:10,代码来源:code_heatmap.py

示例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 
开发者ID:nvdv,项目名称:vprof,代码行数:9,代码来源:memory_profiler.py


注:本文中的sys.gettrace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。