title: How do I use a non-exponential backoff strategy for retries in python requests?
body: <p>I want to make use of the requests module backoff strategy outlined at <a href="https://stackoverflow.com/a/35504626/1021819">https://stackoverflow.com/a/35504626/1021819</a>, the code reproduced from that answer being:</p>
  
  <pre class="lang-py prettyprint-override"><code>import requests
  from urllib3.util.retry import Retry
  from requests.adapters import HTTPAdapter
  
  s = requests.Session()
  
  retries = Retry(total=5,
                  backoff_factor=0.1,
                  status_forcelist=[ 500, 502, 503, 504 ])
  
  s.mount('http://', HTTPAdapter(max_retries=retries))
  
  s.get('http://httpstat.us/500')
  </code></pre>
  
  <p>[This link gives further useful info: <a href="https://www.peterbe.com/plog/best-practice-with-retries-with-requests]" rel="nofollow noreferrer">https://www.peterbe.com/plog/best-practice-with-retries-with-requests]</a></p>
  
  <p>According to the documentation for backoff_factor at <a href="https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#module-urllib3.util.retry" rel="nofollow noreferrer">https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#module-urllib3.util.retry</a>, </p>
  
  <blockquote>
    <p>A backoff factor to apply between attempts after the second try (most errors are resolved immediately by a second try without a delay). urllib3 will sleep for:
    <code>{backoff factor} * (2 ** ({number of total retries} - 1))</code>
    seconds. If the backoff_factor is 0.1, then sleep() will sleep for [0.0s, 0.2s, 0.4s, …] between retries. It will never be longer than Retry.BACKOFF_MAX.</p>
  </blockquote>
  
  <p><strong>How can I elegantly implement a non-exponential backoff e.g. linear?</strong></p>
  
  <p>Thanks as ever!</p>