billiard
billiard copied to clipboard
Cannot call inspect.getinnerframes on Traceback instance
ExceptionInfo
creates a Traceback
instance from the traceback provided by sys.exc_info
and then throws the traceback away. This is inconvenient because some tools (in my case, https://github.com/MindscapeHQ/raygun4py/ calls inspect.getinnerframes
on the provided traceback) want to inspect the traceback of an error to get info for error reporting, but the Traceback
instance cannot be inspected by functions like inspect.getinnerframes
.
Either a reference to the original traceback object or somehow subclassing the built-in class would make it a lot easier to plug these errors into error reporting libraries that expect native traceback objects.
CC @jotes
@Osmose it looks like there's no easy way to inherit "traceback" object. I don't know specifics why this is done that way internally. "inspect" module has function called istraceback
which checks if received object is an instance of TracebackType. Unfortunately, i don't know if there's a simple way to create object which inherits traceback "class" from cPython.
There's a lot of ways we could deal with that: monkey patching of inspect module, rewrite some parts of code in raygun4py to use, try to solve this issue somehow in billiard (i believe that @ask could have some neat ideas where we should go with this issue).
Pickling the raw traceback is way to brittle since it will contain the local variables of every frame, so we recreate the traceback without the locals.
As @jotes write, inspect.getinnerframes
uses inspect.istraceback
which hardocdes the type, and
the type it checks for: types.TracebackType
, cannot be subclassed for some crazy reason:
>>> class X(types.TracebackType):
... pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
type 'traceback' is not an acceptable base type
Unless we would want to copy lots of code from the inspect module, the only way would be to monkey patch inspect.istraceback
:(