Re: Synchronization methodology



Marc 'BlackJack' Rintsch <bj_666@xxxxxxx> wrote:

You may want to make sure the lock will be released in case of an
exception:

def foo(self):
self.lock.aquire()
try:
pass # code
finally:
self.lock.release()


In Python 2.5 this can also be written more succintly using the with
statement so foo becomes:

from __future__ import with_statement
....

def foo(self):
with self.lock:
pass # insert your code here


or write a decorator.
.



Relevant Pages

  • Re: Python 3K or Python 2.9?
    ... function/method argument that might as well be hidden in the compiler ... You could add some syntax to Python such that '.x' was equivalent to ... def factory: ... C.method = foo ...
    (comp.lang.python)
  • Re: a Python persons experience with Ruby
    ... I would like to say firstly that I've been using python for a few ... As for ruby, I think the opcodes will help me clarify... ... Notice that #new and #foo are both CALL ops. ... def a; 2; end ...
    (comp.lang.python)
  • Re: a Python persons experience with Ruby
    ... I would like to say firstly that I've been using python for a few ... As for ruby, I think the opcodes will help me clarify... ... Notice that #new and #foo are both CALL ops. ... def a; 2; end ...
    (comp.lang.python)
  • Destructors and exceptions
    ... locals appears to be deferred to program exit. ... The only rationale I can think of is to speed up exception ... class Foo: ... def premature_exit: ...
    (comp.lang.python)
  • virtual metaclasses explanation
    ... def ClassA ... class ClassB < ClassC ... stuart = ClassB.methodY ... def m1"foo" end ...
    (comp.lang.ruby)