Python Open-Source Snippets Newsletter

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Python Open-Source Snippets Newsletter


I am creating a Python newsletter showcasing useful code snippets from
popular open-source libraries. I will also be providing a runnable demo
link to better understand the working.

Newsletter link:

A sample snippet from the newsletter:

HTTP Request retrying with Backoffs - Technique for retrying failed HTTP

 From Google Maps Services Python

Demo link:

first_request_time: The time of the first request (None if no retries
have occurred).
retry_counter: The count of retries, or zero for the first attempt.

if not first_request_time:
     first_request_time =

elapsed = - first_request_time
if elapsed > self.retry_timeout:
     raise googlemaps.exceptions.Timeout()

if retry_counter > 0:
     # 0.5 * (1.5 ^ i) is an increased sleep time of 1.5x per iteration,
     # starting at 0.5s when retry_counter=0. The first retry will occur
     # at 1, so subtract that first.
     delay_seconds = 0.5 * 1.5 ** (retry_counter - 1)

     # Jitter this value by 50% and pause.
     time.sleep(delay_seconds * (random.random() + 0.5))

Feedbacks and criticism are welcome.
Python-announce-list mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Member address: [hidden email]