[Python-Dev] Asynchronous use of Traceback objects
Michael Hudson
mwh at python.net
Sun Sep 4 12:39:38 CEST 2005
Christopher Armstrong <radeex at gmail.com> writes:
> I had the idea to create a fake Traceback object in Python that
> doesn't hold references to any frame objects, but is still able to be
> passed to 'raise' and formatted as tracebacks are, etc. Unfortunately,
> raise does a type check on its third argument and, besides, it seems
> the traceback formatting functions are very reliant on the internal
> structure of traceback objects, so that didn't work.
An option you may not have considered is to ditch the C code that
formats tracebacks and always use traceback.py (this has a few obvious
problems -- what do you do if traceback.py fails to import, what if
formatting the traceback raises an error -- but nothing too
horrendous, I think).
Less duplication and less C code are always good things (IMHO, at
least).
> It does seem that I would be able to construct a passable fake
> Traceback object from C code -- one that had references to fake
> frames. These fake objects would only remember the original line
> numbers, filenames and so forth so that traceback printing could still
> work. I can try implementing this soon, but I'd just like to make sure
> I'm on the right track. For example, perhaps a better idea would be to
> change the traceback-printing functions to use Python attribute lookup
> instead of internal structure lookup,
My suggestion above would obviously acheive this bit :)
> and then change raise to accept arbitrary Python objects as its
> third argument, as long as it matches the traceback interface. That
> would probably mean much more work, though.
>
> One concern is that I really don't like requiring C modules to use
> Twisted; all of the ones currently in there are optional.
Well, presumably this is optional too -- you only need it if you want
informative tracebacks...
> What's the likelihood of such a traceback-constructor getting its
> way into CPython if I do implement it?
I'd support more flexibility in this area. I'm not sure what the best
approach is, though.
Cheers,
mwh
--
I have *both* hands clapping, but I'm still not sure it's a sound.
When I tried deciding if it were a sound while clapping only one
hand, I fell off my chair.
-- Peter Hansen, Zen master, comp.lang.python
More information about the Python-Dev
mailing list