[Python-Dev] BaseException pickle issue (original) (raw)
Eric Huss ehuss at ironport.com
Sun Apr 1 01:44:16 CEST 2007
- Next message: [Python-Dev] BaseException pickle issue
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Some subclasses of Exception are no longer pickleable in Python 2.5. An example:
class A(Exception): def init(self, foo): self.foo = foo
The key problem here is if you do not somehow set self.args to the correct arguments (via Exception.init or setting self.args directly), you will get a TypeError when you try to unpickle it:
TypeError: init() takes exactly 2 arguments (1 given)
I do not think this is unusual. I found a few examples in Python's standard library that have this problem:
subprocess.CalledProcessError HTMLParser.HTMLParseError httplib.UnknownProtocol, httplib.IncompleteRead, httplib.BadStatusLine optparse.OptParseError pickle._Stop and on and on...
Does anyone have any thoughts about this? Is it a bug?
I can imagine one could argue that exceptions should call the base init method to properly set args, but there are so many exceptions out there that do not do this that it would be very difficult to track them all down.
I removed the reduce and setstate methods from BaseException and everything seems to just work. Pickling/unpickling works for all protocols whether or not you set self.args. Is this an appropriate solution? I'm not sure what the motivation for having these methods is.
-Eric
- Next message: [Python-Dev] BaseException pickle issue
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]