Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31092
| References | <CAAGqYJ22hAdr3-UVeXM_TEwfP_uGu8JoCdh_LHjWOyH2cRphwQ@mail.gmail.com> <mailman.2019.1349831812.27098.python-list@python.org> <nl5gk9-0t5.ln1@satorlaser.homedns.org> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2012-10-10 13:21 -0600 |
| Subject | Re: an error in python lib? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2038.1349896903.27098.python-list@python.org> (permalink) |
On Wed, Oct 10, 2012 at 6:18 AM, Ulrich Eckhardt <ulrich.eckhardt@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 win32 Type "help", "copyright", "credits" or "license" for more information. >>> from threading import Lock >>> lock = Lock() >>> lock.acquire(0) True >>> lock.acquire(0) False > 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?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: an error in python lib? MRAB <python@mrabarnett.plus.com> - 2012-10-10 02:16 +0100
Re: an error in python lib? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-10 14:18 +0200
Re: an error in python lib? Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-10 13:21 -0600
Re: an error in python lib? Wenhua Zhao <whzhao@gmail.com> - 2012-10-11 15:06 -0700
Re: an error in python lib? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-12 09:15 +0200
csiph-web