summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-10-25 04:04:37 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-10-25 04:04:37 (GMT)
commit9a1b956deaddb06341d6cbfa16af9d4eee196e99 (patch)
treedce21295fb88932b9cdfdf5e082c07b8fd4ae1ca
parent1fafc1a11f7d4799f252a40e608b0fd4d4fedb68 (diff)
parent64c1c0720170dbd78dbac333d4c268439ac856bc (diff)
downloadcpython-9a1b956deaddb06341d6cbfa16af9d4eee196e99.zip
cpython-9a1b956deaddb06341d6cbfa16af9d4eee196e99.tar.gz
cpython-9a1b956deaddb06341d6cbfa16af9d4eee196e99.tar.bz2
merge heads
-rw-r--r--Lib/multiprocessing/pool.py6
-rw-r--r--Lib/test/test_multiprocessing.py14
-rw-r--r--Misc/NEWS6
-rw-r--r--Objects/dictobject.c16
4 files changed, 37 insertions, 5 deletions
diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py
index e450319..04e7c44 100644
--- a/Lib/multiprocessing/pool.py
+++ b/Lib/multiprocessing/pool.py
@@ -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
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
index 6940d0e..45bf454 100644
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -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
#
diff --git a/Misc/NEWS b/Misc/NEWS
index 3909420..cd8c9bf 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.3?
Core and Builtins
-----------------
+- Issue #13018: Fix reference leaks in error paths in dictobject.c.
+ Patch by Suman Saha.
+
- Issue #1294232: In a few cases involving metaclass inheritance, the
interpreter would sometimes invoke the wrong metaclass when building a new
class object. These cases now behave correctly. Patch by Daniel Urban.
@@ -58,6 +61,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.
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 3fa5cc4..79894e5 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1314,14 +1314,18 @@ dict_fromkeys(PyObject *cls, PyObject *args)
PyObject *key;
Py_hash_t hash;
- if (dictresize(mp, Py_SIZE(seq)))
+ if (dictresize(mp, Py_SIZE(seq))) {
+ Py_DECREF(d);
return NULL;
+ }
while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) {
Py_INCREF(key);
Py_INCREF(value);
- if (insertdict(mp, key, hash, value))
+ if (insertdict(mp, key, hash, value)) {
+ Py_DECREF(d);
return NULL;
+ }
}
return d;
}
@@ -1332,14 +1336,18 @@ dict_fromkeys(PyObject *cls, PyObject *args)
PyObject *key;
Py_hash_t hash;
- if (dictresize(mp, PySet_GET_SIZE(seq)))
+ if (dictresize(mp, PySet_GET_SIZE(seq))) {
+ Py_DECREF(d);
return NULL;
+ }
while (_PySet_NextEntry(seq, &pos, &key, &hash)) {
Py_INCREF(key);
Py_INCREF(value);
- if (insertdict(mp, key, hash, value))
+ if (insertdict(mp, key, hash, value)) {
+ Py_DECREF(d);
return NULL;
+ }
}
return d;
}