Skip to content

Commit fcf81fd

Browse files
committed
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.
1 parent cfbcec3 commit fcf81fd

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

Doc/library/_thread.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ It defines the following constants and functions:
3535

3636
Raised on thread-specific errors.
3737

38+
.. versionchanged:: 3.3
39+
This is now a synonym of the built-in :exc:`RuntimeError`.
40+
3841

3942
.. data:: LockType
4043

Lib/test/test_threading.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,10 @@ def test_daemonize_active_thread(self):
685685
thread.start()
686686
self.assertRaises(RuntimeError, setattr, thread, "daemon", True)
687687

688+
def test_releasing_unacquired_lock(self):
689+
lock = threading.Lock()
690+
self.assertRaises(RuntimeError, lock.release)
691+
688692

689693
class LockTests(lock_tests.LockTests):
690694
locktype = staticmethod(threading.Lock)

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Core and Builtins
3535
Library
3636
-------
3737

38+
- Issue #11140: Lock.release() now raises a RuntimeError when attempting
39+
to release an unacquired lock, as claimed in the threading documentation.
40+
The _thread.error exception is now an alias of RuntimeError.
41+
3842
- Issue 8594: ftplib now provides a source_address parameter to specify which
3943
(address, port) to bind to before connecting.
4044

Modules/_threadmodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,9 @@ PyInit__thread(void)
13081308

13091309
/* Add a symbolic constant */
13101310
d = PyModule_GetDict(m);
1311-
ThreadError = PyErr_NewException("_thread.error", NULL, NULL);
1311+
ThreadError = PyExc_RuntimeError;
1312+
Py_INCREF(ThreadError);
1313+
13121314
PyDict_SetItemString(d, "error", ThreadError);
13131315
Locktype.tp_doc = lock_doc;
13141316
Py_INCREF(&Locktype);

0 commit comments

Comments
 (0)