o
ai# @ s d dl Z d dlZd dlZd dlmZ ejrd dlmZ G dd de jZG dd deZ G dd d e Z
G d
d deZG dd
d
eZG dd deZ
G dd deZG dd deZG dd deZdS ) N)_utils)RetryCallStatec @ sJ e Zd ZdZejdddefddZdd d
Zdd de j
d fdd
ZdS ) wait_basez(Abstract base class for wait strategies.retry_stater returnc C s d S N selfr r r /builddir/build/BUILDROOT/alt-python310-pip-21.3.1-5.el8.x86_64/opt/alt/python310/lib/python3.10/site-packages/pip/_vendor/tenacity/wait.py__call__ s zwait_base.__call__otherwait_combinec C s
t | |S r )r r
r
r r r __add__"
zwait_base.__add__)r r c C s |dkr| S | |S Nr )r r r r r __radd__% s
zwait_base.__radd__N)r
r r r )__name__
__module____qualname____doc__abcabstractmethodfloatr r typingUnionr r r r r r s
r c @ s4 e Zd ZdZdeddfddZdddefd d
ZdS )
wait_fixedzCWait strategy that waits a fixed amount of time between each retry.waitr Nc C
|| _ d S r r )r
r r r r __init__/ r zwait_fixed.__init__r r c C s | j S r r r r r r r 2 s zwait_fixed.__call__)r r r r r r! r r r r r r , r c s" e Zd ZdZd fddZ ZS ) wait_nonez7Wait strategy that doesn't wait at all before retrying.r Nc s t d d S r )superr! )r
__class__r r r! 9 s zwait_none.__init__)r N)r r r r r!
__classcell__r r r% r r# 6 s r# c @ sN e Zd ZdZddejeef dejeef ddfdd Zd
ddefdd
Z dS )wait_randomzAWait strategy that waits a random amount of time between min/max.r minmaxr Nc C s || _ || _d S r )wait_random_minwait_random_max)r
r* r+ r r r r! @ s
zwait_random.__init__r r c C s | j t | j| j S r )r, randomr- r r r r r D s zwait_random.__call__)r r) )
r r r r r r intr r! r r r r r r( = s ,r( c @ 4 e Zd ZdZdeddfddZdddefd d
ZdS )r z#Combine several waiting strategies.
strategiesr Nc G r r )
wait_funcsr
r1 r r r r! K r zwait_combine.__init__r r c s t fdd| jD S )Nc 3 s | ]}| d V qdS )r Nr ).0xr4 r r O s z(wait_combine.__call__..)sumr2 r r r4 r r N s zwait_combine.__call__r r r r r r! r r r r r r r H r" r c @ r0 )
wait_chaina Chain two or more waiting strategies.
If all strategies are exhausted, the very last strategy is used
thereafter.
For example::
@retry(wait=wait_chain(*[wait_fixed(1) for i in range(3)] +
[wait_fixed(2) for j in range(5)] +
[wait_fixed(5) for k in range(4)))
def wait_chained():
print("Wait 1s for 3 attempts, 2s for 5 attempts and 5s
thereafter.")
r1 r Nc G r r )r1 r3 r r r r! b r zwait_chain.__init__r r c C s0 t t|jdt| j}| j|d }||dS )Nr) r4 )r* r+ attempt_numberlenr1 )r
r wait_func_no wait_funcr r r r e s
zwait_chain.__call__r9 r r r r r: R s r: c @ sd e Zd ZdZddejfdejee f dejee f dejee f ddfd d
Z
ddde fd
dZdS )wait_incrementingzWait an incremental amount of time after each attempt.
Starting at a starting value and incrementing by a value for each attempt
(and restricting the upper limit to some maximum value).
r d start incrementr+ r Nc C s || _ || _|| _d S r )rA rB r+ )r
rA rB r+ r r r r! r s
zwait_incrementing.__init__r r c C s( | j | j|jd }tdt|| jS Nr) r )rA rB r; r+ r* )r
r resultr r r r | s zwait_incrementing.__call__r r r r r MAX_WAITr r r/ r r! r r r r r r? k s
r? c @ st e Zd ZdZdejddfdejee f dejee f dejee f dejee f d d
f
ddZ
d
dd e fddZd
S )wait_exponentiala Wait strategy that applies exponential backoff.
It allows for a customized multiplier and an ability to restrict the
upper and lower limits to some maximum and minimum value.
The intervals are fixed (i.e. there is no jitter), so this strategy is
suitable for balancing retries against latency when a required resource is
unavailable for an unknown duration, but *not* suitable for resolving
contention between multiple processes for a shared resource. Use
wait_random_exponential for the latter case.
r) r
multiplierr+ exp_baser* r Nc C s || _ || _|| _|| _d S r )rI r* r+ rJ )r
rI r+ rJ r* r r r r! s
zwait_exponential.__init__r r c C sR z| j |jd }| j| }W n ty | j Y S w ttd| jt|| jS rC )rJ r; rI
OverflowErrorr+ r* )r
r exprD r r r r s
zwait_exponential.__call__rE r r r r rG s$
rG c s* e Zd ZdZdddef fddZ ZS )wait_random_exponentiala Random wait with exponentially widening window.
An exponential backoff strategy used to mediate contention between multiple
uncoordinated processes for a shared resource in distributed systems. This
is the sense in which "exponential backoff" is meant in e.g. Ethernet
networking, and corresponds to the "Full Jitter" algorithm described in
this blog post:
https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
Each retry occurs at a random time in a geometrically expanding interval.
It allows for a custom multiplier and an ability to restrict the upper
limit of the random interval to some maximum value.
Example::
wait_random_exponential(multiplier=0.5, # initial window 0.5s
max=60) # max 60s timeout
When waiting for an unavailable resource to become available again, as
opposed to trying to resolve contention for a shared resource, the
wait_exponential strategy (which uses a fixed interval) may be preferable.
r r r c s t j|d}td|S )Nr4 r )r$ r r. uniform)r
r highr% r r r s z wait_random_exponential.__call__)r r r r r r r' r r r% r rM s rM )r r. r pip._vendor.tenacityr
TYPE_CHECKINGr ABCr r r# r( r r: r? rG rM r r r r s
"