This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Itay.Brandes
Recipients Itay.Brandes
Date 2012-05-22.08:51:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1337676670.99.0.0296506896441.issue14881@psf.upfronthosting.co.za>
In-reply-to
Content
multiprocessing.dummy crashes when attempting to create a ThreadPool from a Thread.

The following code will crush on 2.7.3:

    import multiprocessing.dummy
    import threading
     
    class Worker(threading.Thread):
        def __init__(self):
            threading.Thread.__init__(self)
     
        def run(self):
            poll = multiprocessing.dummy.Pool(5)
            print str(poll)
     
    w = Worker()
    w.start()

will crush with the following traceback:

    poll = multiprocessing.dummy.Pool(5)
  File "C:\Python27\lib\multiprocessing\dummy\__init__.py", line 150, in Pool
    return ThreadPool(processes, initializer, initargs)
  File "C:\Python27\lib\multiprocessing\pool.py", line 685, in __init__
    Pool.__init__(self, processes, initializer, initargs)
  File "C:\Python27\lib\multiprocessing\pool.py", line 136, in __init__
    self._repopulate_pool()
  File "C:\Python27\lib\multiprocessing\pool.py", line 199, in _repopulate_pool
    w.start()
  File "C:\Python27\lib\multiprocessing\dummy\__init__.py", line 73, in start
    self._parent._children[self] = None
AttributeError: 'Worker' object has no attribute '_children'

If you have access to the thread itself, you can set the _children attribute youself (w._children = weakref.WeakKeyDictionary()), but it is not possible with threads different from threading.thread (Such as PyQt4's QThread thread, which is essential for GUI programming).

The fix that I found is to edit the Python27\Lib\multiprocessing\dummy\__init__.py file. The crashing code is line number 73.
This line should be nested in an if block:

        if hasattr(self._parent, '_children'):
            self._parent._children[self] = None

That way the code is fixed.
Thanks!
History
Date User Action Args
2012-05-22 08:51:11Itay.Brandessetrecipients: + Itay.Brandes
2012-05-22 08:51:10Itay.Brandessetmessageid: <1337676670.99.0.0296506896441.issue14881@psf.upfronthosting.co.za>
2012-05-22 08:51:10Itay.Brandeslinkissue14881 messages
2012-05-22 08:51:10Itay.Brandescreate