Best way to handle exceptions with try/finally

Maxim Sloyko m.sloyko at
Wed May 24 09:55:32 CEST 2006

I guess the following standard method will help :

class MyLocker(object):
    def __init__(self, lock):
          self.lock = lock

    def __del__(self):

Then whenever you need to acquire a lock:
templock = MyLocker(self.__mutex)

del templock # will release the lock (provided you didn't create an
extra link to this object)

More information about the Python-list mailing list