K iqddlZddlZddlZddlmZej rddlmZGddejZejeejdgeje e fffZ GddeZGd d eZGd d eZGd deZGddeZGddeZGddeZGddeZGddeZy)N)_utils)RetryCallStatecpeZdZdZej dddefdZd dZddde jdfd Z y ) wait_basez(Abstract base class for wait strategies. retry_staterreturncyNselfrs S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/tenacity/wait.py__call__zwait_base.__call__s otherct||Sr ) wait_combiner rs r__add__zwait_base.__add__"sD%((r)rrc2|dk(r|S|j|SNr)rrs r__radd__zwait_base.__radd__%s A:K||E""rN)rrrr) __name__ __module__ __qualname____doc__abcabstractmethodfloatrrtypingUnionrr rrrrsN2 $4   )#k#fll;V.W#rrrcDeZdZdZdej ddfdZdddefdZy) wait_fixedzCWait strategy that waits a fixed amount of time between each retry.waitrNc8tj||_yr )r to_secondsr#)r r$s r__init__zwait_fixed.__init__4s ++D1rrrc|jSr )r#r s rrzwait_fixed.__call__7s r rrrrrtime_unit_typer'rrr rrr#r#1s2M2V222t2$4rr#c$eZdZdZdfd ZxZS) wait_nonez7Wait strategy that doesn't wait at all before retrying.c$t|dyr)superr')r __class__s rr'zwait_none.__init__>s r)rN)rrrrr' __classcell__r/s@rr,r,;sArr,c`eZdZdZ d dej dej ddfdZdddefd Zy) wait_randomzAWait strategy that waits a random amount of time between min/max.minmaxrNcltj||_tj||_yr )rr&wait_random_minwait_random_max)r r4r5s rr'zwait_random.__init__Es* &005%005rrrcx|jtj|j|jz zzSr )r7randomr8r s rrzwait_random.__call__Ks4## MMOt33d6J6JJ K  r)rr)r rrr3r3BsIKLM6((6393H3H6 6  $4  rr3c0eZdZdZdeddfdZdddefdZy) rz#Combine several waiting strategies. strategiesrNc||_yr ) wait_funcsr r=s rr'zwait_combine.__init__T $rrrc@tfd|jDS)Nc30K|] }|yw)rNr ).0xrs r z(wait_combine.__call__..XsG!1--Gs)sumr?r s `rrzwait_combine.__call__WsGtGGGrrrrrrr'rrr rrrrQs/-%I%$%H$4HHrrc0eZdZdZdeddfdZdddefdZy) 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.") r=rNc||_yr )r=r@s rr'zwait_chain.__init__krArrrctt|jdt|j}|j|dz }||S)Nr;rD)r4r5attempt_numberlenr=)r r wait_func_no wait_funcs rrzwait_chain.__call__nsB3{991=s4???ST OOL1$45 [11rrIr rrrKrK[s. %I%$%2$422rrKc eZdZdZddej fdej dej dej ddfd Zd d defd Z y) 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 incrementr5rNctj||_tj||_tj||_yr )rr&rUrVr5)r rUrVr5s rr'zwait_incrementing.__init__{s: &&u- **95$$S)rrrc|j|j|jdz zz}tdt ||jSNr;r)rUrVrNr5r4)r rresults rrzwait_incrementing.__call__s<t~~1K1Ka1OPQ1c&$((+,,r) rrrrrMAX_WAITr*r'rrr rrrSrStsg()+.%+__ *$$*((* " " *  *-$4--rrSc eZdZdZdej ddfdejee fdejdejee fdejd d f d Z d d d e fdZ y )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 multiplierr5exp_baser4rNc||_tj||_tj||_||_yr )r_rr&r4r5r`)r r_r5r`r4s rr'zwait_exponential.__init__s6%$$S)$$S)  rrrc |j|jdz z}|j|z}t t d|j t ||jS#t$r|jcYSwxYwrY)r`rNr_ OverflowErrorr5r4)r rexprZs rrzwait_exponential.__call__sm --K$>$>$BCC__s*F3q$((#S%:;; 88O s+A!!A98A9) rrrrrr[r r!intrr*r'rr rrr]r]s 01%+__-.%& !LLe, ! " " !,,sEz* !  " " !  !<$4<$>$BCC\\C'&0F1c&$((+,, XXF s.A00BB) rrrrrr[rr'rr rrrlrlsb __        -$4--rrl)rr:r tenacityr TYPE_CHECKINGrABCrr!Callablerre WaitBaseTr#r,r3rrKrSr]rgrlr rrrvs"  '##" LL v 016<<s 3KKLL     )  H9H222- -,-i-r