Automatic thread safety for classes (fixed bug w/ exceptions)

Connelly Barnes connellybarnes at yahoo.com
Fri Jun 18 10:07:40 CEST 2004


To properly handle exceptions, the code in the previous posting should
be modified to include a try...finally block:

  def ubthreadfunction(f):
    def g(self, *args, **kwargs):
      try:
        self.lock.acquire()
        ans = f(self, *args, **kwargs)
      finally:
        self.lock.release()
      return ans
    return g

 - Connelly



More information about the Python-list mailing list