o ƚRe#@sddlZddlZddlZddlmZejrddlmZGdddejZGdddeZ Gdd d e Z Gd d d eZ Gd d d eZ GdddeZ GdddeZGdddeZGdddeZdS)N)_utils)RetryCallStatec@sJeZdZdZejdddefddZdd d Zddde j d fd d Z dS) wait_basez(Abstract base class for wait strategies. retry_staterreturncCsdSNselfrrr/builddir/build/BUILDROOT/alt-python310-pip-21.3.1-3.el8.x86_64/opt/alt/python310/lib/python3.10/site-packages/pip/_vendor/tenacity/wait.py__call__szwait_base.__call__other wait_combinecCs t||Sr)rr r rrr __add__" zwait_base.__add__)rrcCs|dkr|S||SNr)rrrrr __radd__%s zwait_base.__radd__N)r rrr) __name__ __module__ __qualname____doc__abcabstractmethodfloatr rtypingUnionrrrrr rs  rc@s4eZdZdZdeddfddZdddefd d ZdS) wait_fixedzCWait strategy that waits a fixed amount of time between each retry.waitrNcC ||_dSrr)r rrrr __init__/rzwait_fixed.__init__rrcCs|jSrr r rrr r 2szwait_fixed.__call__)rrrrrr!r rrrr r,rcs"eZdZdZdfdd ZZS) wait_nonez7Wait strategy that doesn't wait at all before retrying.rNcstddSr)superr!)r  __class__rr r!9szwait_none.__init__)rN)rrrrr! __classcell__rrr%r r#6sr#c@sNeZdZdZddejeefdejeefddfdd Zd d defd d Z dS) wait_randomzAWait strategy that waits a random amount of time between min/max.rminmaxrNcCs||_||_dSr)wait_random_minwait_random_max)r r*r+rrr r!@s zwait_random.__init__rrcCs|jt|j|jSr)r,randomr-r rrr r Dszwait_random.__call__)rr)) rrrrrrintrr!r rrrr r(=s,r(c@4eZdZdZdeddfddZdddefd d ZdS) rz#Combine several waiting strategies. strategiesrNcGrr) wait_funcsr r1rrr r!Krzwait_combine.__init__rrcstfdd|jDS)Nc3s|]}|dVqdS)rNr).0xr4rr Osz(wait_combine.__call__..)sumr2r rr4r r Nszwait_combine.__call__rrrrrr!rr rrrr rHr"rc@r0) wait_chainaChain 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.") r1rNcGrr)r1r3rrr r!brzwait_chain.__init__rrcCs0tt|jdt|j}|j|d}||dS)Nr)r4)r*r+attempt_numberlenr1)r r wait_func_no wait_funcrrr r es zwait_chain.__call__r9rrrr r:Rsr:c @sdeZdZdZddejfdejee fdejee fdejee fddfd d Z d d de fd dZ dS)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). rdstart incrementr+rNcCs||_||_||_dSr)rArBr+)r rArBr+rrr r!rs zwait_incrementing.__init__rrcCs(|j|j|jd}tdt||jSNr)r)rArBr;r+r*)r rresultrrr r |szwait_incrementing.__call__ rrrrrMAX_WAITrrr/rr!r rrrr r?ks     r?c @steZdZdZdejddfdejee fdejee fdejee fdejee fd d f d d Z d dd e fddZ d S)wait_exponentialaWait 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*rNcCs||_||_||_||_dSr)rIr*r+rJ)r rIr+rJr*rrr r!s zwait_exponential.__init__rrcCsRz|j|jd}|j|}Wn ty|jYSwttd|jt||jSrC)rJr;rI OverflowErrorr+r*)r rexprDrrr r s  zwait_exponential.__call__rErrrr rGs$      rGcs*eZdZdZdddeffdd ZZS)wait_random_exponentialaRandom 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. rrrcstj|d}td|S)Nr4r)r$r r.uniform)r rhighr%rr r s z wait_random_exponential.__call__)rrrrrr r'rrr%r rMsrM)rr.rpip._vendor.tenacityr TYPE_CHECKINGrABCrrr#r(rr:r?rGrMrrrr s     "