4 ms·
One big thing that's missing from this list is the __traceback__ on exceptions, which pretty much does what you think it does. In Python 2, there's no way to ac
by KerrickStaley 9y ago
One big thing that's missing from this list is the __traceback__ on exceptions, which pretty much does what you think it does. In Python 2, there's no way to access the traceback for an exception once you've left the `except:` block. This matters when you're using things like gevent; if one of your gevent greenlets throws an exception and you inspect the .exception attribute on it, you'll be able to get the exception message but won't know what line it came from.
N.B. This is absent from Python 2 due to concerns with creating self-referential loops. The garbage collector got better in the meantime and the feature was never backported to Python 2.
- jsmthrowaway 9y agoHuh, I was almost sure you were wrong and that I'd done this before, but the frame does indeed "go away" once you leave the except block. Fascinating. In [8]: try: crasher() ...: except TypeError as e: ...: exc = e ...: In [9]: type(exc) Out[9]: TypeError In [10]: traceback.print_tb(exc) AttributeError: 'exceptions.TypeError' object has no attribute 'tb_frame' I can understand the concern, though it seems like there would be easier fixes than the garbage collector for that specific case.
- est 9y ago> there's no way to access the traceback for an exception once you've left the `except:` block Also in 2.4 if you assign a variable to a local inside a traceback it might leak memory.