473,545 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linenumbers: inspect.getinne rframes vs. traceback.forma t_exception

Hi,

the line numbers of inspect.getinne rframes are
different from traceback.forma t_exception.

This results in wrong lines being shown in cgitb.

An example is below.

I looked at the source of both methods. One uses f_lineno (wrong)
the other tb_lineno (correct).

I use python 2.3.3

Is this fixed in a newer version?

See:
===> python tb.py
Correct traceback (traceback.form at_exception)
Traceback (most recent call last):
File "tb.py", line 34, in ?
main()
File "tb.py", line 18, in main
printtb()
File "tb.py", line 13, in printtb
assert(0)
AssertionError
Wrong traceback (inspect.getinn erframe)
File "tb.py", line 34, ...
if __name__=="__ma in__":
File "tb.py", line 18, ...
printtb()
File "tb.py", line 15, ...
pass

tb.py:
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
# Python Imports
import os
import sys
import inspect
import traceback

def printtb():
try:
assert(0)
except ValueError:
pass

def main():
printtb()

class Hook:
def __call__(self, etype, evalue, etb):
print "Correct traceback (traceback.form at_exception)"
print ''.join(traceba ck.format_excep tion(etype, evalue, etb))
print
print "Wrong traceback (inspect.getinn erframe)"
context=5
records = inspect.getinne rframes(etb, context)
for frame, file, lnum, func, lines, index in records:
print ' File "%s", line %s, ...\n%s' % (
file, lnum, lines[context/2].rstrip())

if __name__=="__ma in__":
sys.excepthook= Hook()
main()

Jul 18 '05 #1
1 2538
Am Mon, 11 Oct 2004 13:29:30 +0200 schrieb Thomas Guettler:
Hi,

the line numbers of inspect.getinne rframes are
different from traceback.forma t_exception.


Found the fix in the CVS:

Revision 1.47.8.1 - (view) (download) (as text) (annotate) - [select for
diffs] Sat Jun 5 14:14:48 2004 UTC (4 months ago) by akuchling Branch:
release23-maint
Changes since 1.47: +3 -1 lines
Diff to previous 1.47

[Bug #954364] inspect.getfram einfo() sometimes produces incorrect traceback line #s;
fix is to look at tb.tb_lineno, not tb.frame.f_line no. Patch from Robin
Becker and me.

Thomas

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3872
by: John Hunter | last post by:
What is the best way to get the traceback as a string. I tried def exception_to_str(s = None): sh = StringIO.StringIO() if s is not None: print >>sh, s traceback.print_stack(sh) return sh.getvalue()
1
2025
by: Oliver Walczak | last post by:
This seems to be a quite difficult approach. Try this: ##################################################################### import traceback class MyTraceback: def __init__(self): self.clear() def clear(self): self.s = '' def write(self, s):
1
1626
by: Thomas Guettler | last post by:
Hi, Sometimes the linenumbers of a traceback are wrong. See this traceback. I don't use any attribute "key" here. The method search_dict does not use this attribute, too. Traceback (most recent call last): File "/mnt/raid/modarch/workflow/python/lib/python2.3/site-packages/quixote/publish.py", line 553, in publish output =...
7
2224
by: Robin Becker | last post by:
def raise_an_error(): a = 3 b = 4 c = 0 try: a = a/c except: import sys, cgitb, traceback, inspect tbt,tbv,tb = sys.exc_info() print 'traceback\n',''.join(traceback.format_exception(tbt,tbv,tb))
6
2452
by: EAS | last post by:
Hi, I'm wondering if there is any way to keep a program running when it runs into an error (using the 'try' structure) and print the traceback to the screen? Thanks.
4
1828
by: Hans Georg Krauthaeuser | last post by:
Dear all, I have a problem to get the command that has called a function if the command was given on multiple lines. E.g.: ################################################### import inspect def call(a,b,c,d,e): s = inspector()
1
2262
by: Josh Close | last post by:
When sys.excepthook is called, type, value and traceback are passed into it. How do I get the values of traceback? I've tried printing it, but I get the memory location. I'm gussing there are some methods to use on it. >From what I can tell the traceback that's passed in works differently from the module traceback. I just need to get...
2
1613
by: Fernando Perez | last post by:
Hi all, IPython has suffered quite a few problems with the inspect module in python 2.3. For these, unfortunately all I've been able to do is guard with overreaching except clauses, as I had not been able to find small, reproducible examples to pass on to the devs. But today I got a crash report from a user and I've been able to replicate...
0
1625
by: Stef Mientki | last post by:
Gabriel Genellina wrote: REALLY GREAT ! But this is fully beyond my understanding: m = getmembers ( wx ) print m runs fine print getmembers ( wx )
0
7484
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7928
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7440
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5997
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5344
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3470
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.