New submission from aaugustin <aymeric.augus...@polyconseil.fr>:

The docs for the threading module state that:

> The release() method should only be called in the locked state; it changes 
> the state to unlocked and returns immediately. If an attempt is made to 
> release an unlocked lock, a RuntimeError will be raised.

However, I noticed that catching RuntimeError does not work. Actually release() 
raises thread.error, which inherits directly Exception.

I reproduced the behavior shown below in Python 2.6.6, 2.7.1 from MacPorts on 
Mac OS 10.6 and in Python 2.6.6 on Linux. The same happens in Python 3.2rc2 on 
Mac OS 10.6, except the thread module has been renamed to _thread so the 
exception becomes a _thread.error.

>>> import threading

>>> try:
...     threading.Lock().release()
... except RuntimeError:
...     pass
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
thread.error: release unlocked lock

>>> try:
...     threading.Lock().release()
... except Exception, e:
...     print type(e)
...     print type(e).mro()
... 
<class 'thread.error'>
[<class 'thread.error'>, <type 'exceptions.Exception'>, <type 
'exceptions.BaseException'>, <type 'object'>]

I do not know if this must be fixed in the docs or the code. Currently, the 
type of the exception is probably platform-dependant since the thread module is 
not provided on all platforms.

----------
components: Library (Lib)
messages: 128128
nosy: aaugustin
priority: normal
severity: normal
status: open
title: Error in the documentation of threading.Lock().release()
versions: Python 2.6, Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11140>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to