If an error occurs in a try: finally: block, the normal
traceback prints the correct line number, but the cgitb
module prints the error as if it occurred in the last
line of the finally: block.
Example code:
====================
import cgitb
cgitb.enable()
try:
0//0
finally:
print "This is not where the exception occurred!"
=====================
Traceback correctly reports the error in line 5, but
cgitb reports line 7.
I am using python-2.3.4 on Debian/Linux.
Probable cause: the inspect module, in getframeinfo,
uses the f_lineno attribute from the frame object.
This is what is printed in the cgitb trace. The
traceback module uses the tb_lineno object of the
traceback object itself, which is correct.
Workaround: I am now working around this by using
tb.tb_lineno in inspect.getframeinfo if a traceback
object was passed, and f.f_lineno if a frame object was
passed. I do not have sufficient insight in the code to
foresee any other problems with this fix.
|