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


Groups > comp.lang.python > #17389

Re: Make a small function thread safe

From Lie Ryan <lie.1296@gmail.com>
Subject Re: Make a small function thread safe
Date 2011-12-17 09:08 +1100
References <10d3d04f-1708-4942-8e69-92b715f01ff8@p20g2000vbm.googlegroups.com> <1324042394.23801.6.camel@tim-laptop> <CAF-oDbFg_yuMB=vgz8ZhmWHxTqY7A7JOkXFWbERyioHvLa=h2Q@mail.gmail.com> <CAF-oDbF2xXiBk6oK7gmA=vJQ7Lt3vDB3p9Ckq3nMNihgXt=fNQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3754.1324073306.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 12/17/2011 01:30 AM, Brad Tilley wrote:
> Or perhaps run should look like this instead:
>
>      def run(t):
>          lock.acquire()
>          shared_container.append(t.name <http://t.name>)
>          lock.release()
>
> That seems a bit barbaric to me, not sure.

change that to:

def run(t):
     with lock:
         shared_container.append(t.name <http://t.name>)


the `with-statement` will call lock.acquire() and lock.release().

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


Thread

Make a small function thread safe Brad Tilley <kj4eit@gmail.com> - 2011-12-16 05:21 -0800
  Re: Make a small function thread safe Tim Wintle <tim.wintle@teamrubber.com> - 2011-12-16 13:33 +0000
  Re: Make a small function thread safe Tim Wintle <tim.wintle@teamrubber.com> - 2011-12-16 14:36 +0000
    Re: Make a small function thread safe Brad Tilley <kj4eit@gmail.com> - 2011-12-16 07:05 -0800
  Re: Make a small function thread safe Lie Ryan <lie.1296@gmail.com> - 2011-12-17 09:08 +1100
    Re: Make a small function thread safe John Nagle <nagle@animats.com> - 2011-12-16 18:18 -0800
      Re: Make a small function thread safe RangerElf <gustavo.cordova@gmail.com> - 2011-12-18 00:52 -0800
        Re: Make a small function thread safe Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-18 23:57 -0700
  Re: Make a small function thread safe ting@thsu.org - 2011-12-19 15:56 -0800

csiph-web