summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-09-25 16:45:42 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-09-25 16:45:42 (GMT)
commit3095f4724ec7ca735dfae5c9bd3925c27688a115 (patch)
tree668e6da00578ed86004a27bd300833e3a3cb8730 /Lib/multiprocessing
parent3331a20464d7018e8e0b0f7710690dd1575be3b6 (diff)
downloadcpython-3095f4724ec7ca735dfae5c9bd3925c27688a115.zip
cpython-3095f4724ec7ca735dfae5c9bd3925c27688a115.tar.gz
cpython-3095f4724ec7ca735dfae5c9bd3925c27688a115.tar.bz2
raise a ValueError instead of an AssertionError when pool is an invalid state
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r--Lib/multiprocessing/pool.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py
index 9e07e32..ec57939 100644
--- a/Lib/multiprocessing/pool.py
+++ b/Lib/multiprocessing/pool.py
@@ -225,7 +225,6 @@ class Pool(object):
Apply `func` to each element in `iterable`, collecting the results
in a list that is returned.
'''
- assert self._state == RUN
return self._map_async(func, iterable, mapstar, chunksize).get()
def starmap(self, func, iterable, chunksize=None):
@@ -234,7 +233,6 @@ class Pool(object):
be iterables as well and will be unpacked as arguments. Hence
`func` and (a, b) becomes func(a, b).
'''
- assert self._state == RUN
return self._map_async(func, iterable, starmapstar, chunksize).get()
def starmap_async(self, func, iterable, chunksize=None, callback=None,
@@ -242,7 +240,6 @@ class Pool(object):
'''
Asynchronous version of `starmap()` method.
'''
- assert self._state == RUN
return self._map_async(func, iterable, starmapstar, chunksize,
callback, error_callback)
@@ -250,7 +247,8 @@ class Pool(object):
'''
Equivalent of `map()` -- can be MUCH slower than `Pool.map()`.
'''
- assert self._state == RUN
+ if self._state != RUN:
+ raise ValueError("Pool not running")
if chunksize == 1:
result = IMapIterator(self._cache)
self._taskqueue.put((((result._job, i, func, (x,), {})
@@ -268,7 +266,8 @@ class Pool(object):
'''
Like `imap()` method but ordering of results is arbitrary.
'''
- assert self._state == RUN
+ if self._state != RUN:
+ raise ValueError("Pool not running")
if chunksize == 1:
result = IMapUnorderedIterator(self._cache)
self._taskqueue.put((((result._job, i, func, (x,), {})
@@ -287,7 +286,8 @@ class Pool(object):
'''
Asynchronous version of `apply()` method.
'''
- assert self._state == RUN
+ if self._state != RUN:
+ raise ValueError("Pool not running")
result = ApplyResult(self._cache, callback, error_callback)
self._taskqueue.put(([(result._job, None, func, args, kwds)], None))
return result
@@ -297,7 +297,6 @@ class Pool(object):
'''
Asynchronous version of `map()` method.
'''
- assert self._state == RUN
return self._map_async(func, iterable, mapstar, chunksize)
def _map_async(self, func, iterable, mapper, chunksize=None, callback=None,
@@ -305,6 +304,8 @@ class Pool(object):
'''
Helper function to implement map, starmap and their async counterparts.
'''
+ if self._state != RUN:
+ raise ValueError("Pool not running")
if not hasattr(iterable, '__len__'):
iterable = list(iterable)