code: def synchronize (lock, func, log_duration_secs=0):
      
      def newfunc (*args, **kwargs):
          """Execute function synchronized."""
          t = time.time()
          with lock:
              duration = time.time() - t
              if duration > log_duration_secs > 0:
                  print("WARN:", func.__name__, "locking took %0.2f seconds" % duration, file=sys.stderr)
              return func(*args, **kwargs)
      return update_func_meta(newfunc, func)
docs: Return synchronized function acquiring the given lock.