Castrated traceback in sys.exc_info()

Pascal Chambon chambon.pascal at gmail.com
Wed Mar 17 08:42:06 EDT 2010


Hello,

traceback functions indeed allow the manipulation of exception tracebacks,
but the root problem is that anyway, since that traceback is incomplete,
your "traceback.format_exc().splitlines()" will only provide frames for
callee (downward) functions, not caller (upward) ones, starting from the
exception catching frame.

Regards,
Pascal



2010/3/17 Michael Ricordeau <michael.ricordeau at gmail.com>

> Hi,
>
> to log tracebacks, you can probably try traceback module.
>
> I use it like this :
>
> import traceback
> .... # your code
>
> for line in traceback.format_exc().splitlines():
>  log.trace(line)
>
>
>
> Le Wed, 17 Mar 2010 03:42:44 -0700 (PDT),
> Pakal <chambon.pascal at gmail.com> a écrit :
>
> > Hello
> >
> > I've just realized recently that sys.exc_info() didn't return a full
> > traceback for exception concerned : it actually only contains the
> > frame below the point of exception catching.
> >
> > That's very annoying to me, because I planned to log such tracebacks
> > with logging.critical(*****, exc_info=True), and these partial
> > tracebacks, like the one below, are clearly unsufficient to determine
> > where the problem comes from. A whole traceback, from program entry
> > point to exception raising point, would be much better.
> >
> > 2010-03-17 09:28:59,184 - pims - CRITICAL - This is just a test to
> > ensure critical emails are properly sent
> > Traceback (most recent call last):
> > << HERE, lots of frames missing >>
> >   File "test_common.py", line 34, in test_email_sending
> >     os.open("qsdsdqsdsdqsd", "r")
> > TypeError: an integer is required
> >
> > Is there any workaround for this ? I've thought about a custom logging
> > formatter, which would take both the exc_info traceback AND its own
> > full backtrace, and to connect them together on their relevant part,
> > but it's awkward and error prone... why can't we just have all the
> > precious traceback info under the hand there (an additional attribute
> > might have pointed the precise frame in which the exception was
> > caught).
> >
> > Tanks for the attention,
> > Regards,
> > Pascal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100317/e5dbffe4/attachment.html>


More information about the Python-list mailing list