diff -r 768234f5c246 Lib/multiprocessing/pool.py --- a/Lib/multiprocessing/pool.py Sat Jun 25 15:03:52 2011 +0200 +++ b/Lib/multiprocessing/pool.py Sat Jun 25 18:46:01 2011 +0200 @@ -347,17 +347,16 @@ class Pool(object): if set_length: debug('doing set_length()') set_length(i+1) continue break else: debug('task handler got sentinel') - try: # tell result handler to finish when cache is empty debug('task handler sending sentinel to result handler') outqueue.put(None) # tell workers there is no more work debug('task handler sending sentinel to workers') for p in pool: @@ -575,16 +574,17 @@ class MapResult(ApplyResult): ApplyResult.__init__(self, cache, callback, error_callback=error_callback) self._success = True self._value = [None] * length self._chunksize = chunksize if chunksize <= 0: self._number_left = 0 self._ready = True + del cache[self._job] else: self._number_left = length//chunksize + bool(length % chunksize) def _set(self, i, success_result): success, result = success_result if success: self._value[i*self._chunksize:(i+1)*self._chunksize] = result self._number_left -= 1 diff -r 768234f5c246 Lib/test/test_multiprocessing.py --- a/Lib/test/test_multiprocessing.py Sat Jun 25 15:03:52 2011 +0200 +++ b/Lib/test/test_multiprocessing.py Sat Jun 25 18:46:01 2011 +0200 @@ -1093,16 +1093,22 @@ class _TestPool(BaseTestCase): self.assertEqual(papply(sqr, (), {'x':3}), sqr(x=3)) def test_map(self): pmap = self.pool.map self.assertEqual(pmap(sqr, list(range(10))), list(map(sqr, list(range(10))))) self.assertEqual(pmap(sqr, list(range(100)), chunksize=20), list(map(sqr, list(range(100))))) + # Pass an empty sequence to pool.map issue #12157. + p = multiprocessing.Pool(1) + p.map(sqr, []) + p.close() + p.join() + 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,))