code: def aws_retry(f):
      def retry_wrapper(self, *args, **kwargs):
          last_exc = None
          for i in range(S3_RETRY_COUNT + 1):
              try:
                  ret = f(self, *args, **kwargs)
                  if TEST_S3_RETRY and i == 0:
                      raise Exception(
                          "TEST_S3_RETRY env var set. "
                          "Pretending that an S3 op failed. "
                          "This is not a real failure."
                      )
                  else:
                      return ret
              except MetaflowException as ex:
                  # MetaflowExceptions are not related to AWS, don't retry
                  raise
              except Exception as ex:
                  try:
                      function_name = f.func_name
                  except AttributeError:
                      function_name = f.__name__
                  if TEST_S3_RETRY and i == 0:
                      # This is applicable when this code is being tested
                      sys.stderr.write(
                          "[WARNING] S3 datastore operation %s failed (%s). "
                          "Retrying %d more times..\n"
                          % (function_name, ex, S3_RETRY_COUNT - i)
                      )
                  if i + 1 > RETRY_WARNING_THRESHOLD:
                      # In a real failure, print this warning message only after a certain
                      # amount of retries
                      sys.stderr.write(
                          "[WARNING] S3 datastore operation %s failed (%s). "
                          "Retrying %d more times..\n"
                          % (function_name, ex, S3_RETRY_COUNT - i)
                      )
                  self.reset_client(hard_reset=True)
                  last_exc = ex
                  # exponential backoff for real failures
                  if not (TEST_S3_RETRY and i == 0):
                      time.sleep(2**i + random.randint(0, 5))
          raise last_exc
  
      return retry_wrapper
  
file_path: metaflow/metaflow/plugins/datatools/s3/s3util.py
imports: from __future__ import print_function
  from datetime import datetime
  import random
  import time
  import sys
  import os
  from metaflow.exception import MetaflowException
  from metaflow.metaflow_config import DATATOOLS_CLIENT_PARAMS, DATATOOLS_SESSION_VARS, S3_RETRY_COUNT, RETRY_WARNING_THRESHOLD
label_desc: Use image node_id 2 for calling a global function with example usage: aws_retry(f) and returns: retry_wrapper, ret