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


Groups > comp.lang.python > #75898

Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'callback': 0.09; 'release,': 0.09; 'cc:addr:python-list': 0.11; '"release': 0.16; 'defer': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'stack:': 0.16; 'subject: \n ': 0.16; 'subject:lock': 0.16; 'subject:when': 0.16; 'two.': 0.16; 'unexpected': 0.16; 'exception': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'acquired': 0.19; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'could': 0.34; 'common': 0.35; 'received:google.com': 0.35; 'happen': 0.63; 'between': 0.67; 'atomic': 0.84; 'to:none': 0.92; 'race': 0.95
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:cc :content-type; bh=Fanm/bojI6yil2W/8cud4cOHJqWRp3u7dqoEjU1y9mQ=; b=R72EuUe4Zv55oblOmqSKpCrIpkQbhmSRH1EURDo7hhYxlV4npfhbxqd7DHHOm1Gv5E zEbIKTMvklpb+XKio/3n0YFk1PmlvexlzU0+F0eC4rdP6TE6ki0ie7Mhbnd6DnyBDsCS MAwf+CFd2oYi8+OVaKdIX7ltSnL/2Fi/Nl07483afcL4xohWiooDlrDVCwNy513Jp2I2 vLNu/W3lv9gvuBUeM+mVXxInxAEo7ARCtOW6ZM4rVJNBhFQwZkeZgQdkaokj1sAVoq80 w5MIS4qnsg0kcjUPO2UPT266xXltdd4ZSQ9Eih22G3W4234cOejVT+zR4VAnAL3Tp55A FS0w==
MIME-Version 1.0
X-Received by 10.42.216.148 with SMTP id hi20mr13075134icb.12.1407514614197; Fri, 08 Aug 2014 09:16:54 -0700 (PDT)
In-Reply-To <ls2sh7$eip$1@ger.gmane.org>
References <ff17939d-84cc-4f86-a5b9-9056d76dc9c0@googlegroups.com> <53E4CFD9.4080209@stoneleaf.us> <ls2sh7$eip$1@ger.gmane.org>
Date Sat, 9 Aug 2014 02:16:54 +1000
Subject Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12756.1407514617.18130.python-list@python.org> (permalink)
Lines 14
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407514617 news.xs4all.nl 2898 [2001:888:2000:d::a6]:46068
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75898

Show key headers only | View raw


On Sat, Aug 9, 2014 at 2:05 AM, Neil D. Cerutti <neilc@norwich.edu> wrote:
> Perhaps defer release, a la a common Go pattern:
>
> with contextlib.ExitStack() as stack:
>     acquired = lock.acquire(blocking=False)
>     if acquired:
>         stack.callback(lock.release)
>         do_stuff

There's a race condition in that - an unexpected exception could
happen between those two. Are you able to set the callback to be a
"release if acquired" atomic operation?

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Specifying `blocking` and `timeout` when acquiring lock as a context manager cool-RR <ram.rachum@gmail.com> - 2014-08-08 04:51 -0700
  Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager Ethan Furman <ethan@stoneleaf.us> - 2014-08-08 06:25 -0700
  Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager "Neil D. Cerutti" <neilc@norwich.edu> - 2014-08-08 12:05 -0400
  Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager Chris Angelico <rosuav@gmail.com> - 2014-08-09 02:16 +1000
  Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager "Neil D. Cerutti" <neilc@norwich.edu> - 2014-08-08 14:35 -0400
  Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager "Neil D. Cerutti" <neilc@norwich.edu> - 2014-08-08 14:57 -0400
  Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager Chris Kaynor <ckaynor@zindagigames.com> - 2014-08-08 12:07 -0700
  Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-08 13:21 -0600
  Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager Chris Angelico <rosuav@gmail.com> - 2014-08-09 08:57 +1000

csiph-web