The Python Way

Aahz aahz at pythoncraft.com
Thu Mar 28 22:35:47 EST 2002


In article <jjb5-0A3399.14320327032002 at newsstand.cit.cornell.edu>,
Joel Bender  <jjb5 at cornell.edu> wrote:
>
>Thinking of automatic locking concepts, has there been a PEP for 
>synchronized objects like Java?
>
>    class Snorf:
>        def __init__(self):
>            self.lock = lock.lock()
>
>        def doSomething(self,x) synchronize(self.lock):
>            code
>
>It would be nice if the synchronize parameter could be an instance, 
>class or module lock.

There was some discussion of this in the past month (can't remember if
it was c.l.py or python-dev), but no PEP.  Actually, the discussion came
up with something a bit more general, along the lines of pre- and
post-code:

    class MyLock:
        def start:
        def finish:

    using MyLock():
        <code>

The using construct would automatically call the start() and finish()
methods of the MyLock() instance, no matter what exceptions got raised
in <code>.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Why is this newsgroup different from all other newsgroups?



More information about the Python-list mailing list