[issue13751] multiprocessing.pool hangs if any worker raises an Exception whose constructor requires a parameter

sbt report at bugs.python.org
Mon Jan 9 22:27:58 CET 2012


sbt <shibturn at gmail.com> added the comment:

This is not specific to multiprocessing.  It is really an issue with the pickling of exceptions:

  >>> import cPickle
  >>> class BadExc(Exception):
  ...     def __init__(self, a):
  ...         '''Non-optional param in the constructor.'''
  ...         self.a = a
  ...
  >>> a = cPickle.dumps(BadExc(1))
  >>> cPickle.loads(a)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: ('__init__() takes exactly 2 arguments (1 given)', <class '__main__.BadExc'>, ())

I think that when you create a new exception class with an __init__() method, you need to make sure that self.args is set properly by calling the __init__() method of the parent class using the same arguments.  So you can instead do

  class BadExc(Exception):
      def __init__(self, a):
          '''Non-optional param in the constructor.'''
          Exception.__init__(self, a)
          self.a = a

----------
nosy: +sbt

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13751>
_______________________________________


More information about the Python-bugs-list mailing list