[Python-3000] PEP 344: attaching tracebacks to exceptions + pickle (original) (raw)
Collin Winter collinw at gmail.com
Fri Apr 13 05:16:26 CEST 2007
- Previous message: [Python-3000] [Python-Dev] PEP 3118: Extended buffer protocol (new version)
- Next message: [Python-3000] PEP 344: attaching tracebacks to exceptions + pickle
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In 2.x, exceptions are pickle-able; tracebacks, however, are not. If tracebacks are attached to exceptions in Python 3 (as specified in PEP 344), exceptions will no longer be pickle-able.
There are of course options:
Discard an exception's traceback attribute when pickling.
Include traceback in the pickle, but in a more limited form. That is: the hard parts of exceptions (frames, code objects) aren't fully needed to, say, print out a traceback. The following is all you need:
class Code(object): def init(self, code): self.co_filename = code.co_filename self.co_name = code.co_name
class Frame(object): def init(self, frame): self.f_globals = {"file": frame.f_globals["file"]} self.f_code = Code(frame.f_code)
class Traceback(object): def init(self, tb): self.tb_frame = Frame(tb.tb_frame) self.tb_lineno = tb.tb_lineno if tb.tb_next is None: self.tb_next = None else: self.tb_next = Traceback(tb.tb_next)
When pickling an exception, traceback could be replaced with the limited Traceback implementation above.
- Reject the proposal to attach tracebacks to exceptions. (This is my least favorite.)
Thoughts?
Collin Winter
- Previous message: [Python-3000] [Python-Dev] PEP 3118: Extended buffer protocol (new version)
- Next message: [Python-3000] PEP 344: attaching tracebacks to exceptions + pickle
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]