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
func
raises any exception that is inretry_only
, and it has being tried less thanmax_tries
and the time spent executing the function (waiting included) has not reachedmax_time
, the function will be retried.wait
can be a callable or a number. Ifwait
is callable, it must take a single argument with the previous waiting we did (None
for the first retry) and return the number of seconds to wait before retrying.If
wait
is a number, we convert it to a callable withConstantWait(wait)
.See also
If
retry_only
is None, all exceptions (that inherits from Exception) will be retried. Otherwise, only the exceptions inretry_only
will 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
fn
with 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
wait
argument forretrier
. This callable always return the samewait
value.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
wait
argument 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
.