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


Groups > comp.lang.python > #31135

Re: an error in python lib?

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <whzhao@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'acquired': 0.04; 'output': 0.04; 'concurrently': 0.07; 'false.': 0.07; 'api': 0.09; 'python': 0.09; 'thread,': 0.09; 'bug': 0.10; 'def': 0.10; 'subject:error': 0.11; 'thread': 0.11; 'subject:python': 0.11; 'agree.': 0.16; 'eckhardt': 0.16; 'oct': 0.16; 'threading': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'variable': 0.20; 'import': 0.21; 'latter': 0.22; 'demonstrate': 0.23; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'i.e.': 0.27; 'received:209.85.210.46': 0.27; 'message- id:@mail.gmail.com': 0.27; 'this?': 0.28; 'all.': 0.28; '"in': 0.29; 'error': 0.30; 'print': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'decisions': 0.35; 'false': 0.35; 'generic': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'comment': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'different': 0.63; 'making': 0.64; 'to:name:python': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=1S0dmmJ9x6u534v7YgtEsRPyL5x9WkrVnURNR7M5gj4=; b=L4muRaB3k+eHlsIIFthHtualm5lMYC7oyNJkrzk/jExMWXVPAGfa0sWJkbjKN9T/57 Yei1vJdXxYXxcIktmyvzu2Xe1tw8Ec6RUQqk9VJ8x5ODTdz6f3pjg1hjOvgno9ZUmSr/ HcgEsqTjMCTsqJWpC6MwJs6rb9kCHXsmzW2oCY1TLyDj/zvyfofieRfj7uKj8RbZsapw EuOGXuzIYIcjhAOToumcxEf36W+AHaNS3s+q7KZ6UR+EtsYyj+7nauZpezTcYx1ekXp4 mSNsB6BouXzKTBaGT94zbfWKuV+TTndRkynbyZGxJQd+bQgjjcEGdXUzJpNu2E6ei8dU biow==
MIME-Version 1.0
In-Reply-To <CALwzidm6ouGh-VSunL=8E7CzY0d7gThvGu-in9cu01kNY6qTkA@mail.gmail.com>
References <CAAGqYJ22hAdr3-UVeXM_TEwfP_uGu8JoCdh_LHjWOyH2cRphwQ@mail.gmail.com> <mailman.2019.1349831812.27098.python-list@python.org> <nl5gk9-0t5.ln1@satorlaser.homedns.org> <CALwzidm6ouGh-VSunL=8E7CzY0d7gThvGu-in9cu01kNY6qTkA@mail.gmail.com>
Date Thu, 11 Oct 2012 15:06:43 -0700
Subject Re: an error in python lib?
From Wenhua Zhao <whzhao@gmail.com>
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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.2069.1349993211.27098.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1349993211 news.xs4all.nl 6886 [2001:888:2000:d::a6]:52613
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31135

Show key headers only | View raw


> On Wed, Oct 10, 2012 at 6:18 AM, Ulrich Eckhardt
>> 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.

Agree.

On Wed, Oct 10, 2012 at 12:21 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> Can you demonstrate an API bug that is caused by this?

A simple demo of this error is:

-----------8<------------------------8<----------------------
import time
from threading import Condition, Lock, Thread

cv = Condition(Lock())

def do_acquire():
    cv.acquire()
    print "cv acquired in thread"
    time.sleep(5)
    cv.release()
    print "cv released in thread"

thread = Thread(target=do_acquire)
thread.start()

for i in range(10):
    print "in main cv._is_owned: ", cv._is_owned()
    time.sleep(1)
-----------8<------------------------8<----------------------

The condition variable is only acquired in the thread, so in main it should
always print false.  However, my output gives:

$ python test.py
cv acquired in threadin main cv._is_owned:
True
in main cv._is_owned:  True
in main cv._is_owned:  True
in main cv._is_owned:  True
in main cv._is_owned:  True
cv released in thread
in main cv._is_owned:  False
in main cv._is_owned:  False
in main cv._is_owned:  False
in main cv._is_owned:  False
in main cv._is_owned:  False

However, as long as you follow the generic pattern, i.e. always use
acquire() before wait(), this error is not triggered.

Thanks all.
Wenhua

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