Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'win32': 0.03; 'concurrently': 0.07; 'false,': 0.07; 'api': 0.09; 'python': 0.09; 'correct,': 0.09; 'thread,': 0.09; 'bug': 0.10; 'subject:error': 0.11; 'subject:python': 0.11; 'bug,': 0.16; 'eckhardt': 0.16; 'oct': 0.16; 'sources.': 0.16; 'thread.': 0.16; 'threading': 0.16; 'wed,': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'bit': 0.21; 'import': 0.21; 'latter': 0.22; 'runs': 0.22; 'demonstrate': 0.23; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'this?': 0.28; 'locking': 0.29; 'received:209.85.215.46': 0.30; 'returned': 0.30; 'function': 0.30; 'values.': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'built-in': 0.35; 'decisions': 0.35; 'false': 0.35; 'nov': 0.35; 'returning': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'but': 0.36; 'method': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'comment': 0.38; '2010,': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'first': 0.61; 'different': 0.63; 'more': 0.63; 'making': 0.64; '2.7.1': 0.84; 'surface': 0.84; 'to:name:python': 0.84; 'successful.': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=cDzMKQY9JbGIpOlZMnFZ439EStC7eo+PTODvQzUL8E8=; b=fn9fYriwJKgvO81+MJK2RzCINMYgfRf4RHb4YH6Gq1yUxx9jOOW2SRj5x/a1IuWoDH Et180RGJk+QI6eVusV4tyZ2dkGzYslvEQAGOpYYf4rhYEsofsovjbfDqak3i5GOfmK+f 6HSCutN8Im2ACgD9F6/eh8xA2OxiTIvRYDm6OLzDhsBfDIIzG3s/2usafYWQScW6l/1W NdukAXYy10bIktF484vVf2BqIspehMECkbd6mEYZ9DCBw78VtUKoBzOspuxI/8K+XNPX ley5MtagT69NSRmZQifGPttoJJ3EfLW5m/aFMxwVUQwd2LLCLtjfUax/4IigeuIcgg0p DIwQ== MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Wed, 10 Oct 2012 13:21:10 -0600 Subject: Re: an error in python lib? To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349896903 news.xs4all.nl 6969 [2001:888:2000:d::a6]:39850 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31092 On Wed, Oct 10, 2012 at 6:18 AM, Ulrich Eckhardt 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?