• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python sys.gettrace函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_multiple_managers

 def test_multiple_managers(self):
     tm = self.tm
     tm2 = tracerlib.TracerManager()
     with tm:
         with tm2:
             self.assertEqual(2, len(tracerlib._active_managers))
             self.assertIn(tm, tracerlib._active_managers)
             self.assertIn(tm2, tracerlib._active_managers)
             self.assertEqual(tracerlib._global_tracer, sys.gettrace())
         self.assertEqual(1, len(tracerlib._active_managers))
         self.assertEqual(tracerlib._global_tracer, sys.gettrace())
     self.assertEqual(0, len(tracerlib._active_managers))
     self.assertEqual(None, sys.gettrace())
开发者ID:caktus,项目名称:tracerlib,代码行数:13,代码来源:test.py


示例17: _begin

def _begin():
    """Start tracking program state.

    If begin() has previously been called, any labels that occur during this
    execution will also be made visible to previous begin calls.
    """
    sys.settrace(None)
    assert sys.gettrace() is None
    global prev_state
    prev_state = 0
    push_array()
    sys.settrace(tracer)
    assert sys.gettrace() is tracer
开发者ID:DRMacIver,项目名称:glassbox,代码行数:13,代码来源:pure.py


示例18: prepareTestCase

    def prepareTestCase(self, test):
        # TODO Test this for module-level tests
        log.info('Tracing calls from %s', test)

        # Let's assume that this Python interpreter *does* implement
        # sys.gettrace/settrace
        try:
            sys.gettrace()
        except RuntimeError:
            raise SystemError('NoseDive requires sys.settrace')

        tracer = TestTracer(inspect.getmodule(test.test).__file__)
        sys.settrace(tracer)
开发者ID:mattboyer,项目名称:nosedive,代码行数:13,代码来源:depth.py


示例19: wrap

 def wrap(f, self, request, *args, **kwargs):
     #from api.handlers import log
     c_type = request.content_type
     try:
         #data = data_loaders[c_type](request.raw_post_data)[field_name]
         data = decode_from_string(c_type, request.raw_post_data)[field_name]
     except KeyError as e:
         if find_in_root:
             data = decode_from_string(c_type, request.raw_post_data)
             #data = data_loaders[c_type](request.raw_post_data)
         else:
             raise e, sys.gettrace()
     setattr(request, operation, data)
     return f(self, request, *args, **kwargs)
开发者ID:dismorfo,项目名称:NYU-Annotation-Service,代码行数:14,代码来源:utils.py


示例20: test_inject_cleans_up_tracefn_on_except

def test_inject_cleans_up_tracefn_on_except():
    import sys
    old_trace = sys.gettrace()
    @inject(a=5)
    def foo():
        raise Exception()

    try:
        foo()
        assert False, "should have raised an exception"
    except:
        pass
    assert sys.gettrace() == old_trace
    sys.settrace(old_trace)
开发者ID:noisland,项目名称:python-inject,代码行数:14,代码来源:test_inject.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sys.getwindowsversion函数代码示例发布时间:2022-05-27
下一篇:
Python sys.gettotalrefcount函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap