How to increase the depth of the python traceback?

Peter Otten __peter__ at web.de
Tue Jun 3 17:25:15 EDT 2008


Milton wrote:

> How to increase the depth of the python traceback?
> 
> I have some code that gets an exception deep in the python logging
> module and the traceback produced does not go back far enough to show
> my own code. How can the traceback limit be controlled in Python 2.5.
> 
> The docs indicate that there is an attribute in the sys module
> “tracebacklimit” that defaults to 1000 (affectively no limit). I
> cannot find this attribute in the sys module of Python2.5

Just set it yourself:

>>> import sys
>>> sys.tracebacklimit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'tracebacklimit'
>>> sys.tracebacklimit = 3
>>> def bomb(n):
...     if n: bomb(n-1)
...     else: 1/0
...
>>> bomb(100)
Traceback (most recent call last):
  File "<stdin>", line 2, in bomb
  File "<stdin>", line 2, in bomb
  File "<stdin>", line 3, in bomb
ZeroDivisionError: integer division or modulo by zero

Peter



More information about the Python-list mailing list