summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2012-10-27 10:53:02 (GMT)
committerHynek Schlawack <hs@ox.cx>2012-10-27 10:53:02 (GMT)
commit254af2644a90bcabbe2612950dd2a6ef408337be (patch)
tree206fa794d5e883689a94b1856b0084d21ca7d0cc /Lib
parentcc2f0421c70d6a68e026d074b7d1c7fa4d96e6b8 (diff)
downloadcpython-254af2644a90bcabbe2612950dd2a6ef408337be.zip
cpython-254af2644a90bcabbe2612950dd2a6ef408337be.tar.gz
cpython-254af2644a90bcabbe2612950dd2a6ef408337be.tar.bz2
#16307: Fix multiprocessing.Pool.map_async not calling its callbacks
Patch by Janne Karila.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/multiprocessing/pool.py3
-rw-r--r--Lib/test/test_multiprocessing.py17
2 files changed, 19 insertions, 1 deletions
diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py
index ec57939..7f73b44 100644
--- a/Lib/multiprocessing/pool.py
+++ b/Lib/multiprocessing/pool.py
@@ -297,7 +297,8 @@ class Pool(object):
'''
Asynchronous version of `map()` method.
'''
- return self._map_async(func, iterable, mapstar, chunksize)
+ return self._map_async(func, iterable, mapstar, chunksize, callback,
+ error_callback)
def _map_async(self, func, iterable, mapper, chunksize=None, callback=None,
error_callback=None):
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
index e313dd6..b2a964c 100644
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -1642,6 +1642,23 @@ class _TestPool(BaseTestCase):
self.assertEqual(self.pool.starmap_async(mul, tuples).get(),
list(itertools.starmap(mul, tuples)))
+ def test_map_async(self):
+ self.assertEqual(self.pool.map_async(sqr, list(range(10))).get(),
+ list(map(sqr, list(range(10)))))
+
+ def test_map_async_callbacks(self):
+ call_args = self.manager.list() if self.TYPE == 'manager' else []
+ self.pool.map_async(int, ['1'],
+ callback=call_args.append,
+ error_callback=call_args.append).wait()
+ self.assertEqual(1, len(call_args))
+ self.assertEqual([1], call_args[0])
+ self.pool.map_async(int, ['a'],
+ callback=call_args.append,
+ error_callback=call_args.append).wait()
+ self.assertEqual(2, len(call_args))
+ self.assertIsInstance(call_args[1], ValueError)
+
def test_map_chunksize(self):
try:
self.pool.map_async(sqr, [], chunksize=1).get(timeout=TIMEOUT1)