From: Antoine Pitrou Date: Mon, 28 Feb 2011 22:03:34 +0000 (+0000) Subject: Issue #11140: Lock.release() now raises a RuntimeError when attempting X-Git-Tag: v3.3.0a1~3029 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fcf81fd0310ba505c46d33a82f2b782578ed1a98;p=python 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. --- diff --git a/Doc/library/_thread.rst b/Doc/library/_thread.rst index 369e9cd01e..e7e7504c42 100644 --- a/Doc/library/_thread.rst +++ b/Doc/library/_thread.rst @@ -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 diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 13a428d463..029218d210 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index cad8eda36c..a7f162d4be 100644 --- 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. diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 2d3be5dc04..14ed55e31b 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -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);