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


Python sys.gettrace函数代码示例

本文整理汇总了Python中sys.gettrace函数的典型用法代码示例。如果您正苦于以下问题:Python gettrace函数的具体用法?Python gettrace怎么用?Python gettrace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了gettrace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: stop

 def stop(self):
     """Stop this Tracer."""
     if hasattr(sys, "gettrace") and self.warn:
         if sys.gettrace() != self._trace:
             msg = "Trace function changed, measurement is likely wrong: %r"
             self.warn(msg % sys.gettrace())
     sys.settrace(None)
开发者ID:overtherain,项目名称:simpleHttpServer,代码行数:7,代码来源:collector.py

示例2: wrapper

        def wrapper(*args, **kwargs):
            result = []

            def test_func_thread(test_func, *args, **kwargs):
                try:
                    test_func(*args, **kwargs)
                except Exception as e:
                    result.append(e)
                finally:
                    result.append("done")

            test_timer = threading.Timer(interval, result.append, args=("interrupted",))
            test_thread = threading.Thread(target=test_func_thread,
                                           args=(test_func,) + args,
                                           kwargs=kwargs)
            test_thread.setDaemon(not sys.gettrace())  # in debug mode make thread blocking main
            test_thread.start()
            if not sys.gettrace():  # disable this in debug mode
                test_timer.start()
            while True:
                if test_thread.is_alive() and test_timer.is_alive():
                    time.sleep(0.1)
                else:
                    break

            if "interrupted" in result:
                raise Exception("%s did not finish in %s seconds" % (test_func.__name__,
                                                                     interval))
            else:
                test_timer.cancel()
                for test_result in result:
                    if test_result not in ["done", "interrupted"]:
                        raise test_result
开发者ID:EugeniuZ,项目名称:amqp_protocol_debugger,代码行数:33,代码来源:test_protocol.py

示例3: test_trace_merge

def test_trace_merge():
    with hunter.trace(function="a"):
        with hunter.trace(function="b"):
            with hunter.trace(function="c"):
                assert sys.gettrace().handler == When(Q(function="c"), CodePrinter)
            assert sys.gettrace().handler == When(Q(function="b"), CodePrinter)
        assert sys.gettrace().handler == When(Q(function="a"), CodePrinter)
开发者ID:oroulet,项目名称:python-hunter,代码行数:7,代码来源:test_hunter.py

示例4: test_checking

    def test_checking(self):

        def fake_trace(*args):
            return
        old_trace = sys.gettrace()
        sys.settrace(fake_trace)

        with self.assertRaises(AssertionError):
            # We know f1's behavior but we run f2, raise attention on it
            with checking(name='test_check', trace_all=True):
                f2('Traced code')

        # It has created a summary file
        self.assertTrue(os.path.exists('test_check-last-change.txt'))
        with open('test_check-last-change.txt') as f:
            change = f.read()
        change_lines = change.splitlines()
        self.assertEqual(len(change_lines), 1)
        self.assertIn('test_tools:f', change)
        self.assertEqual(change[0], '!')

        # It has put our trace function back
        after_trace = sys.gettrace()
        sys.settrace(old_trace)
        self.assertEqual(after_trace, fake_trace)
开发者ID:naure,项目名称:PuppyParachute,代码行数:25,代码来源:test_tools.py

示例5: test_call_trace

def test_call_trace():
    from syn.base_utils import call_trace, reset_trace, capture, CallTrace

    def foo():
        bar()

    def bar():
        pass

    foo()
    tr = sys.gettrace()
    with capture() as (out, err):
        with reset_trace():
            call_trace()
            foo()
    assert sys.gettrace() is tr

    assert out.getvalue() == 'foo\n bar\n__exit__\n reset_trace\n'
    assert err.getvalue() == ''

    t = CallTrace()
    with capture() as (out, err):
        t(sys._getframe(), 'call', None)
    
    assert out.getvalue() == 'test_call_trace\n'
    assert err.getvalue() == ''
    assert t.indent == 1

    t(sys._getframe(), 'return', None)
    assert t.indent == 0
开发者ID:mbodenhamer,项目名称:syn,代码行数:30,代码来源:test_debug.py

示例6: test_start_and_stop

 def test_start_and_stop(self):
     assert None is sys.gettrace()
     self.tm.start()
     self.assertIn(self.tm, tracerlib._active_managers)
     self.assertEqual(tracerlib._global_tracer, sys.gettrace())
     self.tm.stop()
     assert None is sys.gettrace()
开发者ID:caktus,项目名称:tracerlib,代码行数:7,代码来源:test.py

示例7: check_with_no_trace

def check_with_no_trace():
    if False:
        print('break on check_with_trace')
    frame = sys._getframe()
    if frame.f_trace is not None:
        raise AssertionError('Expected %s to be None' % (frame.f_trace,))

    if sys.gettrace() is not pydevd_frame_tracing.dummy_tracing_holder.dummy_trace_func:
        raise AssertionError('Expected %s to be dummy_trace_func' % (sys.gettrace(),))
开发者ID:Elizaveta239,项目名称:PyDev.Debugger,代码行数:9,代码来源:_debugger_case_frame_eval.py

示例8: stop

 def stop(self):
     self.stopped = True
     if self.thread != threading.currentThread():
         return
     if hasattr(sys, 'gettrace') and self.warn:
         if sys.gettrace() != self._trace:
             msg = 'Trace function changed, measurement is likely wrong: %r'
             self.warn(msg % (sys.gettrace(),))
     sys.settrace(None)
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:9,代码来源:collector.py

示例9: stop

 def stop(self):
     """
     Stop this Tracer.
     """
     if hasattr(sys, "gettrace") and self.log:
         if sys.gettrace() != self._trace:
             msg = "Trace function changed, measurement is likely wrong: %r"
             print >> sys.stdout, msg % sys.gettrace()
     sys.settrace(None)
开发者ID:dcramer,项目名称:peek,代码行数:9,代码来源:tracer.py

示例10: stop

 def stop(self):
     """Stop this Tracer."""
     if hasattr(sys, "gettrace") and self.warn:
         if sys.gettrace() != self._trace:
             msg = "Trace function changed, measurement is likely wrong: %r"
             self.warn(msg % (sys.gettrace(),))
             #--debug
             #from coverage.misc import short_stack
             #self.warn(msg % (sys.gettrace()))#, short_stack()))
     sys.settrace(None)
开发者ID:portante,项目名称:coverage,代码行数:10,代码来源:collector.py

示例11: __call__

 def __call__(self, enable=True):
     if enable:
         try:
             self.thread_local.trace_backup.append(sys.gettrace())
         except AttributeError:
             self.thread_local.trace_backup = []
             self.thread_local.trace_backup.append(sys.gettrace())
         sys.settrace(self._traceit)
     else:
         sys.settrace(self.thread_local.trace_backup.pop())
开发者ID:slipstream,项目名称:SlipStreamClient,代码行数:10,代码来源:debug.py

示例12: test_gettrace

    def test_gettrace(self):
        '''TODO: revisit'''
        self.assertEqual(sys.gettrace(), None)

        def temp_func(*args, **kwargs):
            pass

        sys.settrace(temp_func)
        self.assertEqual(sys.gettrace(), temp_func)
        sys.settrace(None)
        self.assertEqual(sys.gettrace(), None)
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_sys.py

示例13: test_gettrace

def test_gettrace():
    '''TODO: revisit'''
    AreEqual(sys.gettrace(), None)
    
    def temp_func(*args, **kwargs):
        pass
        
    sys.settrace(temp_func)
    AreEqual(sys.gettrace(), temp_func)
    sys.settrace(None)
    AreEqual(sys.gettrace(), None)
开发者ID:calbonaler,项目名称:DLR_Japanese,代码行数:11,代码来源:sys_test.py

示例14: run_thread

 def run_thread():           # pragma: nested
     """Check that coverage is stopping properly in threads."""
     deadline = time.time() + 5
     ident = threading.currentThread().ident
     if sys.gettrace() is not None:
         has_started_coverage.append(ident)
     while sys.gettrace() is not None:
         # Wait for coverage to stop
         time.sleep(0.01)
         if time.time() > deadline:
             return
     has_stopped_coverage.append(ident)
开发者ID:hugovk,项目名称:coveragepy,代码行数:12,代码来源:test_concurrency.py

示例15: test_error_when_set_multiple

    def test_error_when_set_multiple(self):
        self.monitor._profile.replace(self.bar)
        self.assertIs(sys.gettrace(), self.bar)
        self.monitor._profile.replace(self.bar)
        self.assertIs(sys.gettrace(), self.bar)
        self.monitor._profile.recover()

        self.monitor._profile.replace(self.bar)
        self.assertIs(sys.gettrace(), self.bar)
        with self.assertRaises(RuntimeError):
            self.monitor._profile.replace(None)
            self.assertIs(sys.gettrace(), self.bar)
        self.monitor._profile.recover()
开发者ID:sjagoe,项目名称:pikos,代码行数:13,代码来源:test_trace_function_manager.py


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