code: def synchronized(lock):
      
      def wrap(f):
          def synchronize(*args, **kw):
              lock.acquire()
              try:
                  return f(*args, **kw)
              finally:
                  lock.release()
          return synchronize
      return wrap
docs: Synchronization decorator; provide thread-safe locking on a function
      http://code.activestate.com/recipes/465057/