xotl.tools.tasking – Task oriented tools.¶
Task, multitasking, and concurrent programming tools.
Warning
Experimental. API is not settled.
New in version 1.8.0.
-
class
xotl.tools.tasking.retrier(max_tries=None, max_time=None, wait=DEFAULT_WAIT_INTERVAL, retry_only=None)[source]¶ An auto-retrying dispatcher.
A retrier it’s a callable that takes another callable (
func) and its arguments and runs it in an auto-retrying loop.If
funcraises any exception that is inretry_only, and it has being tried less thanmax_triesand the time spent executing the function (waiting included) has not reachedmax_time, the function will be retried.waitcan be a callable or a number. Ifwaitis callable, it must take a single argument with the previous waiting we did (Nonefor the first retry) and return the number of seconds to wait before retrying.If
waitis a number, we convert it to a callable withConstantWait(wait).See also
If
retry_onlyis None, all exceptions (that inherits from Exception) will be retried. Otherwise, only the exceptions inretry_onlywill be retried.Waiting is done with
time.sleep(). Time tracking is done withtime.monotonic().New in version 1.8.2.
-
xotl.tools.tasking.retry(fn, args=None, kwargs=None, *, max_tries=None, max_time=None, wait=DEFAULT_WAIT_INTERVAL, retry_only=None)[source]¶ Run
fnwith args and kwargs in an auto-retrying loop.See
retrier. This is just:>>> retrier(max_tries=max_tries, max_time=max_time, wait=wait, ... retry_only=retry_only)(fn, *args, **kwargs)
New in version 1.8.2.
-
class
xotl.tools.tasking.ConstantWait(wait=DEFAULT_WAIT_INTERVAL)[source]¶ A constant wait algorithm.
Instances are callables that comply with the need of the
waitargument forretrier. This callable always return the samewaitvalue.We never wait less than
MIN_WAIT_INTERVAL.New in version 1.8.2.
Changed in version 1.9.1: Renamed; it was
StandardWait. The old name is kept as a deprecated alias.Changed in version 2.0.1: Renamed; it was
StandardWait. The old name is kept as a deprecated alias.
-
class
xotl.tools.tasking.BackoffWait(wait=DEFAULT_WAIT_INTERVAL, backoff=1)[source]¶ A wait algorithm with an exponential backoff.
Instances are callables that comply with the need of the
waitargument forretrier.At each call the wait is increased by doubling
backoff(given in milliseconds).We never wait less than
MIN_WAIT_INTERVAL.New in version 1.8.2.
-
xotl.tools.tasking.MIN_WAIT_INTERVAL= 0.02¶ The minimal time (in seconds) to wait between retries.
New in version 1.8.2.
-
xotl.tools.tasking.DEFAULT_WAIT_INTERVAL= 0.05¶ The default time (in seconds) to wait between retries.
New in version 1.8.2.
-
class
xotl.tools.tasking.StandardWait¶ A deprecated alias for
ConstantAlias.