0

我在函数中添加了一个 assert(0) 以了解对该函数的函数调用顺序。

前任:

def my_func():
    ...lines of code...
    assert(0)
    ...more lines of code...

日志仅显示以下内容:

Traceback (most recent call last):
  File "/var/www/folder/file.py", line 273, in my_func
    assert(0)
AssertionError

我想查看完整的调用跟踪 - 示例:first_func -> second_func -> my_func

我尝试了回溯库,但它向我显示了相同的堆栈跟踪。请让我知道我在这里缺少什么。

4

1 回答 1

3

traceback为此使用模块。IE

>>> import traceback
>>> def my_func():
...     my_other_func()
... 
>>> def my_other_func():
...     my_third()
... 
>>> def my_third():
...     print "Stack"
...     traceback.print_stack()
...     print "Extracted"
...     print repr(traceback.extract_stack())
... 
>>> 
>>> my_func()
Stack
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in my_func
  File "<stdin>", line 2, in my_other_func
  File "<stdin>", line 3, in my_third
Extracted
[('<stdin>', 1, '<module>', None), 
 ('<stdin>', 2, 'my_func', None), 
 ('<stdin>', 2, 'my_other_func', None), 
 ('<stdin>', 5, 'my_third', None)]
>>> 
于 2012-12-16T17:53:06.297 回答