Message from discussion
an error in python lib?
Received: by 10.180.97.162 with SMTP id eb2mr126462wib.0.1350352660122;
Mon, 15 Oct 2012 18:57:40 -0700 (PDT)
Path: q11ni134324884wiw.1!nntp.google.com!feeder2.cambriumusenet.nl!94.232.116.12.MISMATCH!feed.xsnews.nl!border-2.ams.xsnews.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!216.196.110.144.MISMATCH!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path: <pyt...@mrabarnett.plus.com>
X-Original-To: python-l...@python.org
Delivered-To: python-l...@mail.python.org
X-Spam-Status: OK 0.016
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'else:': 0.03; 'here?':
0.09; 'def': 0.10; 'subject:error': 0.11; 'subject:python': 0.11;
'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16;
'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'received:84.93': 0.16; 'received:84.93.230': 0.16; 'wrote:':
0.17; 'skip:_ 20': 0.22; 'header:In-Reply-To:1': 0.25; 'header
:User-Agent:1': 0.26; 'values': 0.26; "doesn't": 0.28; 'noticed':
0.28; 'received:192.168.1.3': 0.29; 'skip:_ 10': 0.29; 'class':
0.29; 'received:84': 0.32; 'to:addr:python-list': 0.33; 'wrong':
0.34; 'false': 0.35; 'subject:?': 0.35; 'but': 0.36; 'method':
0.36; 'should': 0.36; 'subject:: ': 0.38; 'to:addr:python.org':
0.39; 'release': 0.39; 'received:192': 0.39; 'called': 0.39;
'list,': 0.39; 'received:192.168': 0.40; 'header:Reply-To:1':
0.68; 'reply-to:no real name:2**0': 0.72; 'reply-
to:addr:python.org': 0.84; 'skip:/ 30': 0.91; 'successful.': 0.93
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.0 cv=YaM/Fntf c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=AAvI7MrX_rgA:10 a=DaeUtwAXtUgA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10
a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=6ftMcWHAi6AA:10
a=9z56YbnCAcI3BlPu5XAA:9 a=wPNLvfGTeEIA:10
a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH: mrabarnett:2500
Date: Wed, 10 Oct 2012 02:16:46 +0100
From: MRAB <pyt...@mrabarnett.plus.com>
User-Agent: Mozilla/5.0 (Windows NT 5.1;
rv:15.0) Gecko/20120907 Thunderbird/15.0.1
MIME-Version: 1.0
To: python-l...@python.org
Subject: Re: an error in python lib?
References: <CAAGqYJ22hAdr3-UVeXM_TEwfP_uGu8JoCdh_LHjWOyH2cRp...@mail.gmail.com>
In-Reply-To: <CAAGqYJ22hAdr3-UVeXM_TEwfP_uGu8JoCdh_LHjWOyH2cRp...@mail.gmail.com>
X-BeenThere: python-l...@python.org
X-Mailman-Version: 2.1.15
Precedence: list
Reply-To: python-l...@python.org
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-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-l...@python.org>
List-Help: <mailto:python-list-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-requ...@python.org?subject=subscribe>
Newsgroups: comp.lang.python
Message-ID: <mailman.2019.1349831812.27098.python-l...@python.org>
Lines: 42
NNTP-Posting-Host: 2001:888:2000:d::a6
X-Trace: 1349831812 news.xs4all.nl 6879 [2001:888:2000:d::a6]:53060
X-Complaints-To: ab...@xs4all.nl
Bytes: 4252
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
On 2012-10-10 01:32, Wenhua Zhao wrote:
> Hi list,
>
> I just noticed that in /usr/lib/python2.7/threading.py
>
> class _Condition(_Verbose):
> ...
> def _is_owned(self):
> # Return True if lock is owned by current_thread.
> # This method is called only if __lock doesn't have
> _is_owned().
> if self.__lock.acquire(0):
> self.__lock.release()
> return False
> else:
> return True
>
> The return values seem to be wrong. They should be swapped:
>
> def _is_owned(self):
> if self.__lock.acquire(0):
> self.__lock.release()
> return True
> else:
> return False
>
> Or I understood it wrong here?
>
The .acquire method will return True if the attempt to acquire has been
successful. This can occur only if it is not currently owned.
In pseudocode:
if the attempt to acquire it succeeds:
no-one owed it before, but now I own it
release it
now no-one owns it
return False
else:
someone already owns it
return True