code: def try_repeatedly(method, max_retries=None, delay=None):
      
      max_retries = max_retries if max_retries is not None else 1
      delay = delay if delay is not None else 0
      tries = 0
  
      with warn_only():
          while tries < max_retries:
              res = method()
              if not res.failed:
                  return res
  
              tries += 1
              time.sleep(delay)
      # final try outside the warn_only block so that if it
      # fails it'll just blow up or do whatever it was going to
      # do anyway.
      return method()
docs: Execute the given Fabric call, retrying up to a certain number of times.
  
      The method is expected to be wrapper around a Fabric :func:`run` or :func:`sudo`
      call that returns the results of that call. The call will be executed at least
      once, and up to :code:`max_retries` additional times until the call executes with
      out failing.
  
      Optionally, a delay in seconds can be specified in between successive calls.
  
      :param callable method: Wrapped Fabric method to execute
      :param int max_retries: Max number of times to retry execution after a failed call
      :param float delay: Number of seconds between successive calls of :code:`method`
      :return: The results of running :code:`method`