This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author aymeric.augustin
Recipients aymeric.augustin
Date 2011-02-07.15:35:26
SpamBayes Score 5.551115e-16
Marked as misclassified No
Message-id <1297092927.55.0.763535906906.issue11140@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2011-02-07 15:35:27aymeric.augustinsetrecipients: + aymeric.augustin
2011-02-07 15:35:27aymeric.augustinsetmessageid: <1297092927.55.0.763535906906.issue11140@psf.upfronthosting.co.za>
2011-02-07 15:35:27aymeric.augustinlinkissue11140 messages
2011-02-07 15:35:26aymeric.augustincreate