Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3095f472
Commit
3095f472
authored
Sep 25, 2012
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
raise a ValueError instead of an AssertionError when pool is an invalid state
parent
3331a204
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
Lib/multiprocessing/pool.py
Lib/multiprocessing/pool.py
+8
-7
Lib/test/test_multiprocessing.py
Lib/test/test_multiprocessing.py
+2
-1
No files found.
Lib/multiprocessing/pool.py
View file @
3095f472
...
...
@@ -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
)
...
...
Lib/test/test_multiprocessing.py
View file @
3095f472
...
...
@@ -1727,7 +1727,8 @@ class _TestPool(BaseTestCase):
with
multiprocessing
.
Pool
(
2
)
as
p
:
r
=
p
.
map_async
(
sqr
,
L
)
self
.
assertEqual
(
r
.
get
(),
expected
)
self
.
assertRaises
(
AssertionError
,
p
.
map_async
,
sqr
,
L
)
print
(
p
.
_state
)
self
.
assertRaises
(
ValueError
,
p
.
map_async
,
sqr
,
L
)
def
raising
():
raise
KeyError
(
"key"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment