Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31092

Re: an error in python lib?

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 <ian.g.kelly@gmail.com>
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 <nl5gk9-0t5.ln1@satorlaser.homedns.org>
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 Wed, 10 Oct 2012 13:21:10 -0600
Subject Re: an error in python lib?
To Python <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2038.1349896903.27098.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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