title: Python Adding a retry after exceptions is raised
body: <p>i've inherited a code that needs a bit of a rework. A spectrum scan error keeps happening and this is the place where the exception is raised:</p>
  <pre><code>try:
      # iterate trough each record in json file
      for i in sorted(tables_to_load, key=lambda x: (tables_to_load[x][&quot;order&quot;])):
          # print(i)
          # if table exclude flag is set to &quot;N&quot;, proceed with load_table()
          if tables_to_load[i][&quot;exclude&quot;] == &quot;N&quot;:
              try:
                  job_start_time = datetime.now()
                  logger.info(&quot;Begin load for: %s ---- %s ----&quot; %(tables_to_load[i][&quot;order&quot;], i))
                  error_code = load_table(i, tables_to_load[i], from_date, to_date, max_proc, dm_updated, 
                  process_flag)
                  job_end_time = datetime.now()
                  job_duration = (job_end_time - job_start_time).total_seconds()
                  logger.info(&quot;Load for table: %s -- time: %s seconds.&quot; %(i, job_duration))
              except Exception as e:
                  #this is where the error is cought
                  logger.error(&quot;Load for table: %s FAILED: %s&quot; %(i, e))
                  raise
          #else the table is excluded and we skip it
          else:
              logger.info(&quot;Table excluded from load: %s &quot; %i)
  except Exception as e:
      # upload error log to s3
      s3.upload_file(filepath + filename, s3_logbucket, s3_logprefix + filename)
      raise
  </code></pre>
  <p>Basically, the script reads a json cfg file containing a list of  externatl tables partitioned by YYYYMMDD or YYYYMMDDhhmmss) , RS tables and RS store procedures which load the data from S3 to RS.
  When the error is caught, I don't want the error to be raised. Or rather, I want to give it 3 times before the error is raised. I need help writing that iteration?</p>
  <p>Thanks,
  Rosa</p>