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


Python traceback.walk_stack方法代码示例

本文整理汇总了Python中traceback.walk_stack方法的典型用法代码示例。如果您正苦于以下问题:Python traceback.walk_stack方法的具体用法?Python traceback.walk_stack怎么用?Python traceback.walk_stack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在traceback的用法示例。


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

示例1: _log_trace

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def _log_trace(func, start=None):
    level = 0
    current_frame = None

    # Increase the current level for each traced function in the stackframe
    # This way we can visualize the call stack.
    for frame, _ in traceback.walk_stack(None):
        current_frame = current_frame if current_frame is not None else frame
        func_name = frame.f_code.co_name
        if func_name in _trace_funcs:
            level += 1

    # We can assume we have 'args' because we only call _log_trace inside
    # trace or TraceDispatcher.resgister
    current_op = current_frame.f_locals['args'][0]

    # If the first argument is a Expr, we print its op because it's more
    # informative.
    if isinstance(current_op, ir.Expr):
        current_op = current_op.op()

    _logger.debug(
        f"{'  ' * level} {func.__name__} {type(current_op).__qualname__} "
        f"{datetime.now() - start if start else ''}"
    ) 
开发者ID:ibis-project,项目名称:ibis,代码行数:27,代码来源:trace.py

示例2: __call__

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def __call__(self,*args,**kwargs):
        global RP_TRANSFERRING_FLAG
        if RP_TRANSFERRING_FLAG:
            return self.raw(*args,**kwargs)
        RP_TRANSFERRING_FLAG=True
        if not NET_INITTED:
            return self.raw(*args,**kwargs)
        for stack in traceback.walk_stack(None):
            if 'self' in stack[0].f_locals:
                layer=stack[0].f_locals['self']
                if layer in layer_names:
                    log.pytorch_layer_name=layer_names[layer]
                    print("Processing Layer: "+layer_names[layer])
                    break
        out=self.obj(self.raw,*args,**kwargs)
        RP_TRANSFERRING_FLAG=False
        # if isinstance(out,Variable):
        #     out=[out]
        return out

# ----- for torch.nn.functional operations ----- 
开发者ID:hahnyuan,项目名称:nn_tools,代码行数:23,代码来源:pytorch_to_caffe.py

示例3: get_stack_info

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def get_stack_info():
    '''Capture locals, module name, filename, and line number from the
    stacktrace to provide the source of the assertion error and
    formatted note.
    '''
    stack = traceback.walk_stack(sys._getframe().f_back)

    # We want locals from the test definition (which always begins
    # with 'test_' in unittest), which will be at a different
    # level in the stack depending on how many tests are in each
    # test case, how many test cases there are, etc.

    # The branch where we exhaust this loop is not covered
    # because we always find a test.
    for frame, _ in stack:  # pragma: no branch
        code = frame.f_code
        if code.co_name.startswith('test_'):
            return (frame.f_locals.copy(), frame.f_globals['__name__'],
                    code.co_filename, frame.f_lineno) 
开发者ID:twosigma,项目名称:marbles,代码行数:21,代码来源:_stack.py

示例4: _extract_stack

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def _extract_stack(limit=10):
    """Replacement for traceback.extract_stack() that only does the
    necessary work for asyncio debug mode.
    """
    frame = sys._getframe().f_back
    try:
        stack = traceback.StackSummary.extract(
            traceback.walk_stack(frame), lookup_lines=False)
    finally:
        del frame

    apg_path = asyncpg.__path__[0]
    i = 0
    while i < len(stack) and stack[i][0].startswith(apg_path):
        i += 1
    stack = stack[i:i + limit]

    stack.reverse()
    return ''.join(traceback.format_list(stack)) 
开发者ID:MagicStack,项目名称:asyncpg,代码行数:21,代码来源:connection.py

示例5: test_walk_stack

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def test_walk_stack(self):
        s = list(traceback.walk_stack(None))
        self.assertGreater(len(s), 10) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_traceback.py

示例6: test_extract_stack

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def test_extract_stack(self):
        s = traceback.StackSummary.extract(traceback.walk_stack(None))
        self.assertIsInstance(s, traceback.StackSummary) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_traceback.py

示例7: test_extract_stack_limit

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def test_extract_stack_limit(self):
        s = traceback.StackSummary.extract(traceback.walk_stack(None), limit=5)
        self.assertEqual(len(s), 5) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_traceback.py

示例8: test_format_locals

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def test_format_locals(self):
        def some_inner(k, v):
            a = 1
            b = 2
            return traceback.StackSummary.extract(
                traceback.walk_stack(None), capture_locals=True, limit=1)
        s = some_inner(3, 4)
        self.assertEqual(
            ['  File "%s", line %d, in some_inner\n'
             '    traceback.walk_stack(None), capture_locals=True, limit=1)\n'
             '    a = 1\n'
             '    b = 2\n'
             '    k = 3\n'
             '    v = 4\n' % (__file__, some_inner.__code__.co_firstlineno + 4)
            ], s.format()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_traceback.py

示例9: __call__

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def __call__(self,*args,**kwargs):
        if not NET_INITTED:
            return self.raw(*args,**kwargs)
        for stack in traceback.walk_stack(None):
            if 'self' in stack[0].f_locals:
                layer=stack[0].f_locals['self']
                if layer in layer_names:
                    log.pytorch_layer_name=layer_names[layer]
                    print(layer_names[layer])
                    break
        out=self.obj(self.raw,*args,**kwargs)
        # if isinstance(out,Variable):
        #     out=[out]
        return out 
开发者ID:xxradon,项目名称:PytorchToCaffe,代码行数:16,代码来源:pytorch_to_caffe.py

示例10: extract_stack

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def extract_stack(f=None, limit=None):
    """Replacement for traceback.extract_stack() that only does the
    necessary work for asyncio debug mode.
    """
    if f is None:
        f = sys._getframe().f_back
    if limit is None:
        # Limit the amount of work to a reasonable amount, as extract_stack()
        # can be called for each coroutine and future in debug mode.
        limit = constants.DEBUG_STACK_DEPTH
    stack = traceback.StackSummary.extract(traceback.walk_stack(f),
                                           limit=limit,
                                           lookup_lines=False)
    stack.reverse()
    return stack 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:17,代码来源:format_helpers.py

示例11: __call__

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def __call__(self, *args, **kwargs):
        if not NET_INITTED:
            return self.raw(*args, **kwargs)
        for stack in traceback.walk_stack(None):
            if 'self' in stack[0].f_locals:
                layer = stack[0].f_locals['self']
                if layer in layer_names:
                    log.pytorch_layer_name = layer_names[layer]
                    print(layer_names[layer])
                    break
        out = self.obj(self.raw, *args, **kwargs)
        # if isinstance(out,Variable):
        #     out=[out]
        return out 
开发者ID:JDAI-CV,项目名称:fast-reid,代码行数:16,代码来源:pytorch_to_caffe.py

示例12: test_walk_stack

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def test_walk_stack(self):
        def deeper():
            return list(traceback.walk_stack(None))
        s1 = list(traceback.walk_stack(None))
        s2 = deeper()
        self.assertEqual(len(s2) - len(s1), 1)
        self.assertEqual(s2[1:], s1) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:9,代码来源:test_traceback.py

示例13: _extract_stack_iter

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def _extract_stack_iter(frame):
        for f, lineno in walk_stack(frame):
            co = f.f_code
            filename = co.co_filename
            name = co.co_name
            yield filename, lineno, name 
开发者ID:weka-io,项目名称:easypy,代码行数:8,代码来源:concurrency.py

示例14: _find_marker

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import walk_stack [as 别名]
def _find_marker():
    marker_repr = repr(STACK_TRACE_MARKER)
    stack = traceback.StackSummary.extract(traceback.walk_stack(None), capture_locals=True)
    for frame in stack:
        if 'stack_trace_marker' in frame.locals:
            if frame.locals['stack_trace_marker'] == marker_repr:
                return True
    return False 
开发者ID:zalando-incubator,项目名称:kopf,代码行数:10,代码来源:test_callbacks.py


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