[New-bugs-announce] [issue16855] traceback module leaves off module name in last line of formatted tracebacks

Walter Mundt report at bugs.python.org
Thu Jan 3 22:49:05 CET 2013


New submission from Walter Mundt:

The documentation for the traceback module states that it "exactly mimics the behavior of the Python interpreter when it prints a stack trace."  However, this does not seem to be the case.  In Python 2.7.3, executing the following:

    import socket
    import sys
    import traceback
    
    def raises_socket_timeout():
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(0.001)
        s.connect(('8.8.8.8', 9999))
    
    try:
        raises_socket_timeout()
    except Exception:
        print "print_exc():"
        traceback.print_exc()
        print "-------------"
        print "uncaught:"
        raise

Results in this output:

    print_exc():
    Traceback (most recent call last):
      File "test.py", line 11, in <module>
        raises_socket_timeout()
      File "test.py", line 8, in raises_socket_timeout
        s.connect(('8.8.8.8', 9999))
      File "/usr/lib/python2.7/socket.py", line 224, in meth
        return getattr(self._sock,name)(*args)
    timeout: timed out
    -------------
    uncaught:
    Traceback (most recent call last):
      File "test.py", line 11, in <module>
        raises_socket_timeout()
      File "test.py", line 8, in raises_socket_timeout
        s.connect(('8.8.8.8', 9999))
      File "/usr/lib/python2.7/socket.py", line 224, in meth
        return getattr(self._sock,name)(*args)
    socket.timeout: timed out

Note that the last line of the former message is "timeout: timed out" while the latter is "socket.timeout: timed out" (much more informative).  I've run into this specific difference in trying to debug production systems that use the traceback module to log exceptions.  It also affects traceback.format_exc(), traceback.format_exception_only(), logging.exception(), and logging.info(..., exc_info=True) and friends.

----------
messages: 178991
nosy: waltermundt
priority: normal
severity: normal
status: open
title: traceback module leaves off module name in last line of formatted tracebacks
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16855>
_______________________________________


More information about the New-bugs-announce mailing list