an error in python lib?
ian.g.kelly at gmail.com
Wed Oct 10 21:21:10 CEST 2012
On Wed, Oct 10, 2012 at 6:18 AM, Ulrich Eckhardt
<ulrich.eckhardt at dominolaser.com> wrote:
>> The .acquire method will return True if the attempt to acquire has been
>> successful. This can occur only if it is not currently owned.
> The comment clearly states "owned by current thread", not "owned by any
> thread". The latter would also be useless, as that can change concurrently
> at any time when owned by a different thread, so making decisions on this
> state is futile.
If you're correct, then the bug runs deeper than simply swapping the
return values. If the first case returned True instead of False, then
it would be returning True when the lock is not owned by any thread.
> Also, acquire() can also return true when locking
> recursively, at least that's how I read the sources.
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
Type "help", "copyright", "credits" or "license" for more information.
>>> from threading import Lock
>>> lock = Lock()
> I think that this is really a bug, but it doesn't surface often because the
> built-in lock has its own _is_owned() function which is used instead of this
> flawed logic.
Can you demonstrate an API bug that is caused by this?
More information about the Python-list