def Synchronized(method):
  """Decorator to acquire a mutex around an APIProxyStub method.

  Args:
    method: An unbound method of APIProxyStub or a subclass.

  Returns:
    The method, altered such it acquires self._mutex throughout its execution.
  """

  def WrappedMethod(self, *args, **kwargs):
    with self._mutex:
      return method(self, *args, **kwargs)

  return WrappedMethod