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
f8859e18
Commit
f8859e18
authored
Oct 24, 2011
by
Charles-François Natali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10332: multiprocessing: fix a race condition when a Pool is closed
before all tasks have completed.
parent
d6ca6c2b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
1 deletion
+22
-1
Lib/multiprocessing/pool.py
Lib/multiprocessing/pool.py
+5
-1
Lib/test/test_multiprocessing.py
Lib/test/test_multiprocessing.py
+14
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/multiprocessing/pool.py
View file @
f8859e18
...
...
@@ -321,7 +321,11 @@ class Pool(object):
@
staticmethod
def
_handle_workers
(
pool
):
while
pool
.
_worker_handler
.
_state
==
RUN
and
pool
.
_state
==
RUN
:
thread
=
threading
.
current_thread
()
# Keep maintaining workers until the cache gets drained, unless the pool
# is terminated.
while
thread
.
_state
==
RUN
or
(
pool
.
_cache
and
thread
.
_state
!=
TERMINATE
):
pool
.
_maintain_pool
()
time
.
sleep
(
0.1
)
# send sentinel to stop workers
...
...
Lib/test/test_multiprocessing.py
View file @
f8859e18
...
...
@@ -1217,6 +1217,20 @@ class _TestPoolWorkerLifetime(BaseTestCase):
p
.
close
()
p
.
join
()
def
test_pool_worker_lifetime_early_close
(
self
):
# Issue #10332: closing a pool whose workers have limited lifetimes
# before all the tasks completed would make join() hang.
p
=
multiprocessing
.
Pool
(
3
,
maxtasksperchild
=
1
)
results
=
[]
for
i
in
range
(
6
):
results
.
append
(
p
.
apply_async
(
sqr
,
(
i
,
0.3
)))
p
.
close
()
p
.
join
()
# check the results
for
(
j
,
res
)
in
enumerate
(
results
):
self
.
assertEqual
(
res
.
get
(),
sqr
(
j
))
#
# Test that manager has expected number of shared objects left
#
...
...
Misc/NEWS
View file @
f8859e18
...
...
@@ -58,6 +58,9 @@ Core and Builtins
Library
-------
- Issue #10332: multiprocessing: fix a race condition when a Pool is closed
before all tasks have completed.
- Issue #13255: wrong docstrings in array module.
- Issue #9168: now smtpd is able to bind privileged port.
...
...
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