changeset 68191:2ddca55e098d

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.
author Antoine Pitrou <solipsis@pitrou.net>
date Mon, 28 Feb 2011 22:03:34 +0000
parents b7d62bc01998
children bbddac5c18d3
files Doc/library/_thread.rst Lib/test/test_threading.py Misc/NEWS Modules/_threadmodule.c
diffstat 4 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Doc/library/_thread.rst	Mon Feb 28 19:27:16 2011 +0000
+++ b/Doc/library/_thread.rst	Mon Feb 28 22:03:34 2011 +0000
@@ -35,6 +35,9 @@
 
    Raised on thread-specific errors.
 
+   .. versionchanged:: 3.3
+      This is now a synonym of the built-in :exc:`RuntimeError`.
+
 
 .. data:: LockType
 
--- a/Lib/test/test_threading.py	Mon Feb 28 19:27:16 2011 +0000
+++ b/Lib/test/test_threading.py	Mon Feb 28 22:03:34 2011 +0000
@@ -685,6 +685,10 @@
         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)
--- a/Misc/NEWS	Mon Feb 28 19:27:16 2011 +0000
+++ b/Misc/NEWS	Mon Feb 28 22:03:34 2011 +0000
@@ -35,6 +35,10 @@
 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.
 
--- a/Modules/_threadmodule.c	Mon Feb 28 19:27:16 2011 +0000
+++ b/Modules/_threadmodule.c	Mon Feb 28 22:03:34 2011 +0000
@@ -1308,7 +1308,9 @@
 
     /* 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);