[issue10015] Creating a multiproccess.pool.ThreadPool from a child thread blows up.
Michael Olson
report at bugs.python.org
Sat Oct 2 16:00:29 CEST 2010
New submission from Michael Olson <olson at irinim.net>:
Using Python 2.7 x32 on Windows XP
Attempting to create a multiprocessing.pool.ThreadPool
in a child thread created using threading.Thread, an
AttributeError is thrown. A ThreadPool created in the
main thread can be passed to the child thread and used.
Exact text of exception
-------------------
File "D:\Dev\Python27\lib\multiprocessing\dummy\__init__.py", line 47, in star
t
self._parent._children[self] = None
AttributeError: 'Thread' object has no attribute '_children'
Demonstration Code
-------------------
import unittest
from threading import Thread
from multiprocessing.pool import ThreadPool
def f(x):
return x*x
def create_and_run(cb, pool = None):
if not pool:
pool = ThreadPool(2)
r = pool.map_async(f, range(10))
cb(r.get())
class TestThreadPool(unittest.TestCase):
def setUp(self):
self.expected = [f(x) for x in range(10)]
def callback(self, data):
self.data = data
def test_creating_pool_in_mainthread(self):
"""Test multiprocessing.pool.ThreadPool from main thread"""
self.data = None
create_and_run(self.callback)
self.assertEqual(self.data, self.expected)
def test_creating_pool_in_subthread(self):
"""Test multiprocessing.pool.ThreadPool from a child thread."""
self.data = None
t = Thread(target=create_and_run, args=[self.callback])
t.start()
t.join()
self.assertEqual(self.data, self.expected)
def test_creating_pool_in_subthread_workaround(self):
"""Test running a ThreadPool created in main thread, used in child."""
self.data = None
pool = ThreadPool(2)
t = Thread(target=create_and_run, args=[self.callback, pool])
t.start()
t.join()
self.assertEqual(self.data, self.expected)
if __name__ =='__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestThreadPool)
unittest.TextTestRunner(verbosity=2).run(suite)
----------
components: Library (Lib)
files: potential_issue_demo.py
messages: 117875
nosy: Michael.Olson
priority: normal
severity: normal
status: open
title: Creating a multiproccess.pool.ThreadPool from a child thread blows up.
type: crash
versions: Python 2.7
Added file: http://bugs.python.org/file19105/potential_issue_demo.py
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10015>
_______________________________________
More information about the Python-bugs-list
mailing list