]> granicus.if.org Git - python/commitdiff
merge in patch from tim golden to fix contextmanager support for mp.Lock()
authorJesse Noller <jnoller@gmail.com>
Mon, 30 Mar 2009 23:29:31 +0000 (23:29 +0000)
committerJesse Noller <jnoller@gmail.com>
Mon, 30 Mar 2009 23:29:31 +0000 (23:29 +0000)
Lib/test/test_multiprocessing.py
Misc/ACKS
Misc/NEWS
Modules/_multiprocessing/semaphore.c

index 105a7433c03065c97eaee05704c46d0e3d29ea3d..a446ac304d99fc29cf1d458d638d4d346e692b89 100644 (file)
@@ -546,6 +546,10 @@ class _TestLock(BaseTestCase):
         self.assertEqual(lock.release(), None)
         self.assertRaises((AssertionError, RuntimeError), lock.release)
 
+    def test_lock_context(self):
+        with self.Lock():
+            pass
+
 
 class _TestSemaphore(BaseTestCase):
 
index 426cd9a336c5e8c23b7fe513ba913881daee84d5..6345442b7d53d830fe567b420c679a8a06f134fe 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -256,6 +256,7 @@ Dinu Gherman
 Jonathan Giddy
 Johannes Gijsbers
 Michael Gilfix
+Tim Golden
 Chris Gonnerman
 David Goodger
 Hans de Graaff
@@ -789,4 +790,3 @@ Siebren van der Zee
 Uwe Zessin
 Tarek Ziad\8e
 Peter Åstrand
-Jesse Noller
index b0ae319c54ce095765ffa632b2a9fa3c18902dfb..97753ad2280f971da3ee55045dfb94f8229bcdef 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -199,6 +199,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #5261: Patch multiprocessing's semaphore.c to support context
+  manager use: "with multiprocessing.Lock()" works now.
+
 - Issue #5177: Multiprocessing's SocketListener class now uses 
   socket.SO_REUSEADDR on all connections so that the user no longer needs
   to wait 120 seconds for the socket to expire.
index a5ba71e30ca8f701d138094a93b44b21f7624107..2c2fb10f2810302c1d1536b889273de5465412f6 100644 (file)
@@ -546,7 +546,7 @@ static PyMethodDef semlock_methods[] = {
         "acquire the semaphore/lock"},
        {"release", (PyCFunction)semlock_release, METH_NOARGS, 
         "release the semaphore/lock"},
-       {"__enter__", (PyCFunction)semlock_acquire, METH_VARARGS,
+    {"__enter__", (PyCFunction)semlock_acquire, METH_VARARGS | METH_KEYWORDS,
         "enter the semaphore/lock"},
        {"__exit__", (PyCFunction)semlock_release, METH_VARARGS, 
         "exit the semaphore/lock"},