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: 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: References: Date: Thu, 11 Oct 2012 15:06:43 -0700 Subject: Re: an error in python lib? From: Wenhua Zhao To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 > 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 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