]> granicus.if.org Git - python/commitdiff
Issue #11140: Lock.release() now raises a RuntimeError when attempting
authorAntoine Pitrou <solipsis@pitrou.net>
Mon, 28 Feb 2011 22:03:34 +0000 (22:03 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Mon, 28 Feb 2011 22:03:34 +0000 (22:03 +0000)
to release an unacquired lock, as claimed in the threading documentation.
The _thread.error exception is now an alias of RuntimeError.

Doc/library/_thread.rst
Lib/test/test_threading.py
Misc/NEWS
Modules/_threadmodule.c

index 369e9cd01ec5133af9fa5f7e0a186b9289ba5709..e7e7504c4201a9549d7d6cce20b99f3b9c942bfa 100644 (file)
@@ -35,6 +35,9 @@ It defines the following constants and functions:
 
    Raised on thread-specific errors.
 
+   .. versionchanged:: 3.3
+      This is now a synonym of the built-in :exc:`RuntimeError`.
+
 
 .. data:: LockType
 
index 13a428d463d6389dfa994f7b53016ede51f28deb..029218d21014108dd6795a1da37f8cad361f66aa 100644 (file)
@@ -685,6 +685,10 @@ class ThreadingExceptionTests(BaseTestCase):
         thread.start()
         self.assertRaises(RuntimeError, setattr, thread, "daemon", True)
 
+    def test_releasing_unacquired_lock(self):
+        lock = threading.Lock()
+        self.assertRaises(RuntimeError, lock.release)
+
 
 class LockTests(lock_tests.LockTests):
     locktype = staticmethod(threading.Lock)
index cad8eda36c5a9d764ee7f10086fc6d446ca09360..a7f162d4be0f2be67d1ed94efc9ef9aa108fb3e4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -35,6 +35,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #11140: Lock.release() now raises a RuntimeError when attempting
+  to release an unacquired lock, as claimed in the threading documentation.
+  The _thread.error exception is now an alias of RuntimeError.
+
 - Issue 8594: ftplib now provides a source_address parameter to specify which
   (address, port) to bind to before connecting.
 
index 2d3be5dc04eba19517cedd120f7c291304c4b7e3..14ed55e31b6e26874c02935f68d310e0c05df9c3 100644 (file)
@@ -1308,7 +1308,9 @@ PyInit__thread(void)
 
     /* Add a symbolic constant */
     d = PyModule_GetDict(m);
-    ThreadError = PyErr_NewException("_thread.error", NULL, NULL);
+    ThreadError = PyExc_RuntimeError;
+    Py_INCREF(ThreadError);
+    
     PyDict_SetItemString(d, "error", ThreadError);
     Locktype.tp_doc = lock_doc;
     Py_INCREF(&Locktype);