]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue 6433: multiprocessing.pool.map hangs on empty list
authorJesse Noller <jnoller@gmail.com>
Thu, 16 Jul 2009 14:23:04 +0000 (14:23 +0000)
committerJesse Noller <jnoller@gmail.com>
Thu, 16 Jul 2009 14:23:04 +0000 (14:23 +0000)
Lib/multiprocessing/pool.py
Lib/test/test_multiprocessing.py
Misc/ACKS
Misc/NEWS

index bc7e8f1712e86d420f1412cb39b5d1c41a66a478..b91b77d16d30c56bde2a83b5309e7f419cc13643 100644 (file)
@@ -207,6 +207,8 @@ class Pool(object):
             chunksize, extra = divmod(len(iterable), len(self._pool) * 4)
             if extra:
                 chunksize += 1
+        if len(iterable) == 0:
+            chunksize = 0
 
         task_batches = Pool._get_tasks(func, iterable, chunksize)
         result = MapResult(self._cache, chunksize, len(iterable), callback)
index 1e4a98e4f24b9d3e24343a088e976003a195db46..29c7ff961bec59ad9ecefdb3619b32b71862340c 100644 (file)
@@ -990,6 +990,12 @@ class _TestPool(BaseTestCase):
         self.assertEqual(pmap(sqr, range(100), chunksize=20),
                          map(sqr, range(100)))
 
+    def test_map_chunksize(self):
+        try:
+            self.pool.map_async(sqr, [], chunksize=1).get(timeout=TIMEOUT1)
+        except multiprocessing.TimeoutError:
+            self.fail("pool.map_async with chunksize stalled on null list")
+
     def test_async(self):
         res = self.pool.apply_async(sqr, (7, TIMEOUT1,))
         get = TimingWrapper(res.get)
index 4b1f2909e5fc2b71d478d01bb668540393cebf0c..41d72c1108164091bfa269e487db2ea3def703d4 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -199,6 +199,7 @@ Walter Dörwald
 Hans Eckardt
 Grant Edwards
 John Ehresman
+Eric Eisner
 Andrew Eland
 Lance Ellinghaus
 David Ely
index 51930409e357a7d28c98035b7289f36010f8050b..3e43df58e51abf6115251bd76f418a660430fcbd 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -352,6 +352,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #6433: fixed issues with multiprocessing.pool.map hanging on empty list
+
 - Issue #6314: logging: Extra checks on the "level" argument in more places.
 
 - Issue #2622: Fixed an ImportError when importing email.messsage from a