This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author waltermundt
Recipients waltermundt
Date 2013-01-03.21:49:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1357249745.89.0.552193091281.issue16855@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-01-03 21:49:05waltermundtsetrecipients: + waltermundt
2013-01-03 21:49:05waltermundtsetmessageid: <1357249745.89.0.552193091281.issue16855@psf.upfronthosting.co.za>
2013-01-03 21:49:05waltermundtlinkissue16855 messages
2013-01-03 21:49:05waltermundtcreate