@@ -40,8 +40,7 @@ is raised. Here's an example using exponential backoff when any
4040
4141.. code-block :: python
4242
43- @backoff.on_exception (backoff.expo,
44- requests.exceptions.RequestException)
43+ @backoff.on_exception (backoff.expo, requests.exceptions.RequestException)
4544 def get_url (url ):
4645 return requests.get(url)
4746
@@ -50,9 +49,9 @@ the same backoff behavior is desired for more than one exception type:
5049
5150.. code-block :: python
5251
53- @backoff.on_exception (backoff.expo,
54- (requests.exceptions.Timeout,
55- requests.exceptions.ConnectionError) )
52+ @backoff.on_exception (
53+ backoff.expo, (requests.exceptions.Timeout, requests.exceptions.ConnectionError)
54+ )
5655 def get_url (url ):
5756 return requests.get(url)
5857
@@ -66,9 +65,7 @@ of total time in seconds that can elapse before giving up.
6665
6766.. code-block :: python
6867
69- @backoff.on_exception (backoff.expo,
70- requests.exceptions.RequestException,
71- max_time = 60 )
68+ @backoff.on_exception (backoff.expo, requests.exceptions.RequestException, max_time = 60 )
7269 def get_url (url ):
7370 return requests.get(url)
7471
@@ -78,10 +75,9 @@ to make to the target function before giving up.
7875
7976.. code-block :: python
8077
81- @backoff.on_exception (backoff.expo,
82- requests.exceptions.RequestException,
83- max_tries = 8 ,
84- jitter = None )
78+ @backoff.on_exception (
79+ backoff.expo, requests.exceptions.RequestException, max_tries = 8 , jitter = None
80+ )
8581 def get_url (url ):
8682 return requests.get(url)
8783
@@ -97,10 +93,10 @@ be retried:
9793 def fatal_code (e ):
9894 return 400 <= e.response.status_code < 500
9995
100- @backoff.on_exception (backoff.expo,
101- requests.exceptions.RequestException,
102- max_time = 300 ,
103- giveup = fatal_code )
96+
97+ @backoff.on_exception (
98+ backoff.expo, requests.exceptions.RequestException, max_time = 300 , giveup = fatal_code
99+ )
104100 def get_url (url ):
105101 return requests.get(url)
106102
@@ -118,11 +114,14 @@ case, regardless of the logic in the `on_exception` handler.
118114 def fatal_code (e ):
119115 return 400 <= e.response.status_code < 500
120116
121- @backoff.on_exception (backoff.expo,
122- requests.exceptions.RequestException,
123- max_time = 300 ,
124- raise_on_giveup = False ,
125- giveup = fatal_code)
117+
118+ @backoff.on_exception (
119+ backoff.expo,
120+ requests.exceptions.RequestException,
121+ max_time = 300 ,
122+ raise_on_giveup = False ,
123+ giveup = fatal_code,
124+ )
126125 def get_url (url ):
127126 return requests.get(url)
128127
@@ -217,12 +216,8 @@ backoff behavior for different cases:
217216.. code-block :: python
218217
219218 @backoff.on_predicate (backoff.fibo, max_value = 13 )
220- @backoff.on_exception (backoff.expo,
221- requests.exceptions.HTTPError,
222- max_time = 60 )
223- @backoff.on_exception (backoff.expo,
224- requests.exceptions.Timeout,
225- max_time = 300 )
219+ @backoff.on_exception (backoff.expo, requests.exceptions.HTTPError, max_time = 60 )
220+ @backoff.on_exception (backoff.expo, requests.exceptions.Timeout, max_time = 300 )
226221 def poll_for_message (queue ):
227222 return queue.get()
228223
@@ -245,9 +240,9 @@ runtime to obtain the value:
245240 # and that it has a dictionary-like 'config' property
246241 return app.config[" BACKOFF_MAX_TIME" ]
247242
248- @backoff.on_exception (backoff.expo,
249- ValueError ,
250- max_time = lookup_max_time)
243+
244+ @backoff.on_exception (backoff.expo, ValueError , max_time = lookup_max_time)
245+ def my_function (): ...
251246
252247 Event handlers
253248--------------
@@ -275,13 +270,16 @@ implemented like so:
275270.. code-block :: python
276271
277272 def backoff_hdlr (details ):
278- print (" Backing off {wait:0.1f } seconds after {tries} tries "
279- " calling function {target} with args {args} and kwargs "
280- " {kwargs} " .format(** details))
273+ print (
274+ " Backing off {wait:0.1f } seconds after {tries} tries "
275+ " calling function {target} with args {args} and kwargs "
276+ " {kwargs} " .format(** details)
277+ )
281278
282- @backoff.on_exception (backoff.expo,
283- requests.exceptions.RequestException,
284- on_backoff = backoff_hdlr)
279+
280+ @backoff.on_exception (
281+ backoff.expo, requests.exceptions.RequestException, on_backoff = backoff_hdlr
282+ )
285283 def get_url (url ):
286284 return requests.get(url)
287285
@@ -293,9 +291,11 @@ handler functions as the value of the ``on_backoff`` keyword arg:
293291
294292.. code-block :: python
295293
296- @backoff.on_exception (backoff.expo,
297- requests.exceptions.RequestException,
298- on_backoff = [backoff_hdlr1, backoff_hdlr2])
294+ @backoff.on_exception (
295+ backoff.expo,
296+ requests.exceptions.RequestException,
297+ on_backoff = [backoff_hdlr1, backoff_hdlr2],
298+ )
299299 def get_url (url ):
300300 return requests.get(url)
301301
@@ -343,41 +343,46 @@ as:
343343
344344.. code-block :: python
345345
346- logging.getLogger(' backoff' ).addHandler(logging.StreamHandler())
346+ logging.getLogger(" backoff" ).addHandler(logging.StreamHandler())
347347
348348 The default logging level is INFO, which corresponds to logging
349349anytime a retry event occurs. If you would instead like to log
350350only when a giveup event occurs, set the logger level to ERROR.
351351
352352.. code-block :: python
353353
354- logging.getLogger(' backoff' ).setLevel(logging.ERROR )
354+ logging.getLogger(" backoff" ).setLevel(logging.ERROR )
355355
356356 It is also possible to specify an alternate logger with the ``logger ``
357357keyword argument. If a string value is specified the logger will be
358358looked up by name.
359359
360360.. code-block :: python
361361
362- @backoff.on_exception (backoff.expo,
363- requests.exceptions.RequestException,
364- logger = ' my_logger' )
365- # ...
362+ @backoff.on_exception (
363+ backoff.expo,
364+ requests.exceptions.RequestException,
365+ logger = " my_logger" ,
366+ )
367+ def my_function (): ...
366368
367369 It is also supported to specify a Logger (or LoggerAdapter) object
368370directly.
369371
370372.. code-block :: python
371373
372- my_logger = logging.getLogger(' my_logger' )
374+ my_logger = logging.getLogger(" my_logger" )
373375 my_handler = logging.StreamHandler()
374376 my_logger.addHandler(my_handler)
375377 my_logger.setLevel(logging.ERROR )
376378
377- @backoff.on_exception (backoff.expo,
378- requests.exceptions.RequestException,
379- logger = my_logger)
380- # ...
379+
380+ @backoff.on_exception (
381+ backoff.expo,
382+ requests.exceptions.RequestException,
383+ logger = my_logger,
384+ )
385+ def my_function (): ...
381386
382387 Default logging can be disabled all together by specifying
383388``logger=None ``. In this case, if desired alternative logging behavior
0 commit comments