Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
wait.cpython-313.pyc155 linesDownload Raw Back to __pycache__
1�

2r�j�$���SSKrSSKrSSKrSSKJr \R3(aSSKJr "SS\R5r\R\\RS/\R\\444r
"SS\5r"S	S4\5r"SS\5r"S
S\5r"SS\5r"SS\5r"SS\5r"SS\5r"SS\5r"SS\5rg)�N)�_utils)�RetryCallStatec�~�\rSrSrSr\RSSS\4Sj5rS
Sjr	SSS\5RS	4S6jrSr
g)�	wait_base�z(Abstract base class for wait strategies.�retry_stater�returnc��g�N���selfrs  �SD:\code\apps\devtools\python\user_packages\Python313\site-packages\tenacity/wait.py�__call__�wait_base.__call__s����otherc��[X5$r)�wait_combine�rrs  r�__add__�wait_base.__add__"s
���D�(�(r)rrc�4�US:XaU$URU5$�Nr)rrs  r�__radd__�wait_base.__radd__%s���A�:��K��|�|�E�"�"rrN)rrr	r)�__name__�7__module__�__qualname__�__firstlineno__�__doc__�abc�abstractmethod�floatrr�typing�Unionr�__static_attributes__rrrrrsN��2����
�$4�
��
��
�)�#�k�#�f�l�l�;V�.W�#rrrc�P�\rSrSrSrS\RSS4SjrSSS\4S	jr	S8r9g)�10wait_fixed�1zCWait strategy that waits a fixed amount of time between each retry.�waitr	Nc�:�[R"U5Ulgr)r�11to_secondsr))rr+s  r�__init__�wait_fixed.__init__4s�� �+�+�D�1��rrrc��UR$r�r)r
s  rr�wait_fixed.__call__7s�����rr1�rrrr r!r�time_unit_typer.r$rr'rrrr)r)1s2��M�2�V�2�2�2�t�2��$4���rr)c�0^�\rSrSrSrSU4SjjrSrU=r$)�	wait_none�;z7Wait strategy that doesn't wait at all before retrying.c�$>�[TU]S5 gr)�superr.)r�	__class__s �rr.�wait_none.__init__>s���
����rr)r	N)rrrr r!r.r'�
__classcell__�r:s@rr6r6;s���A��rr6c�n�\rSrSrSrSS\RS\RSS4SjjrSS	S\4S12jr	Sr13g)
�wait_random�BzAWait strategy that waits a random amount of time between min/max.�min�maxr	Nc�p�[R"U5Ul[R"U5Ulgr)rr-�wait_random_min�wait_random_max)rrArBs   rr.�wait_random.__init__Es*�� &�0�0��5���%�0�0��5��rrrc�z�UR[R"5URUR-14--$r)rD�randomrEr
s  rr�wait_random.__call__Ks4���#�#��M�M�O�t�3�3�d�6J�6J�J�K�15�	16r)rErD)r�r3rrrr?r?BsI��K�LM�6��(�(�6�39�3H�3H�6�	
�6�17�$4�18��19rr?c�<�\rSrSrSrS\SS4SjrSSS\4S	jrS20r	g)r�Qz#Combine several waiting strategies.�21strategiesr	Nc��Xlgr��22wait_funcs�rrMs  rr.�wait_combine.__init__T���$�rrrc�B^�[U4SjUR55$)Nc3�.># �UH23o"TS9v� M g7f)�rNr)�.0�xrs  �r�	<genexpr>�(wait_combine.__call__.<locals>.<genexpr>Xs����G��!�1��-��s�)�sumrPr
s `rr�wait_combine.__call__Ws����G�t���G�G�GrrO�24rrrr r!rr.r$rr'rrrrrQs/��-�%�I�%�$�%�H�$4�H��Hrrc�<�\rSrSrSrS\SS4SjrSSS\4S	jrS25r	g)�26wait_chain�[a�Chain two or more waiting strategies.27 28If all strategies are exhausted, the very last strategy is used29thereafter.30 31For example::32 33    @retry(wait=wait_chain(*[wait_fixed(1) for i in range(3)] +34                           [wait_fixed(2) for j in range(5)] +35                           [wait_fixed(5) for k in range(4)]))36    def wait_chained():37        print("Wait 1s for 3 attempts, 2s for 5 attempts and 5s "38              "thereafter.")39rMr	Nc��Xlgr�rMrQs  rr.�wait_chain.__init__krSrrrc��[[URS5[UR55nURUS-40nU"US9$)NrJrV)rArB�attempt_number�lenrM)rr�wait_func_no�	wait_funcs    rr�wait_chain.__call__nsB���3�{�9�9�1�=�s�4�?�?�?S�T���O�O�L�1�$4�5�	��[�1�1rrbr]rrrr_r_[s.��
�%�I�%�$�%�2�$4�2��2rr_c�\�\rSrSrSrS\R\/\4SS4Sjr	SSS\4S	jr41S42rg)�wait_exception�ta�Wait strategy that waits the amount of time returned by the predicate.43 44The predicate is passed the exception object. Based on the exception, the45user can decide how much time to wait before retrying.46 47For example::48 49    def http_error(exception: BaseException) -> float:50        if (51            isinstance(exception, requests.HTTPError)52            and exception.response.status_code == requests.codes.too_many_requests53        ):54            return float(exception.response.headers.get("Retry-After", "1"))55        return 60.056 57 58    @retry(59        stop=stop_after_attempt(3),60        wait=wait_exception(http_error),61    )62    def http_get_request(url: str) -> None:63        response = requests.get(url)64        response.raise_for_status()65�	predicater	Nc��Xlgr�rm)rrms  rr.�wait_exception.__init__�s��"�rrrc��URc[S5eURR5nUc[S5eURU5$)Nz(__call__() called before outcome was setz(outcome failed but the exception is None)�outcome�RuntimeError�	exceptionrm)rrrts   rr�wait_exception.__call__�sO�����&��I�J�J��'�'�1�1�3�	����I�J�J��~�~�i�(�(rro)rrrr r!r%�Callable�
BaseExceptionr$r.rr'rrrrkrkts>���2#�&�/�/�=�/�5�2H�"I�#�d�#�)�$4�)��)rrkc	��\rSrSrSrSS\R4S\RS\RS\RSS	4S66jjrSSS\	4S
jr67Srg	)�wait_incrementing�z�Wait an incremental amount of time after each attempt.68 69Starting at a starting value and incrementing by a value for each attempt70(and restricting the upper limit to some maximum value).71r�d�start�	incrementrBr	Nc��[R"U5Ul[R"U5Ul[R"U5Ulgr)rr-r|r}rB)rr|r}rBs    rr.�wait_incrementing.__init__�s:���&�&�u�-��72��*�*�9�5����$�$�S�)��rrrc��URURURS-73--n[S[	X R55$�NrJr)r|r}rerBrA)rr�results   rr�wait_incrementing.__call__�s:�����t�~�~��1K�1K�a�1O�P�Q���1�c�&�(�(�+�,�,r)r}rBr|)rrrr r!r�MAX_WAITr4r.r$rr'rrrryry�sg���()�+.�%+�_�_�	*��$�$�*��(�(�*��
"�
"�	*�7475�*�-�$4�-��-rryc���\rSrSrSrS\RSS4S\R\	\764S\RS\R\	\774S	\RS78S479SjjrS
SS80\814Sjr
Srg)�wait_exponential�a�Wait strategy that applies exponential backoff.82 83It allows for a customized multiplier and an ability to restrict the84upper and lower limits to some maximum and minimum value.85 86The intervals are fixed (i.e. there is no jitter), so this strategy is87suitable for balancing retries against latency when a required resource is88unavailable for an unknown duration, but *not* suitable for resolving89contention between multiple processes for a shared resource. Use90wait_random_exponential for the latter case.91rJ�r�92multiplierrB�exp_baserAr	Nc��Xl[R"U5Ul[R"U5UlX0lgr)r�rr-rArBr�)rr�rBr�rAs     rr.�wait_exponential.__init__�s2��%���$�$�S�)����$�$�S�)��� �
rrrc���URURS-93-nURU-n[	[	SUR945[X0R55$![a URs$f=fr�)r�rer��
OverflowErrorrBrA)rr�expr�s    rr�wait_exponential.__call__�sk��	��-�-�K�$>�$>��$B�C�C��_�_�s�*�F��3�q�$�(�(�#�S����%:�;�;���	��8�8�O�	�s�+A � A9�8A9)r�rBrAr�)rrrr r!rr�r%r&�intr$r4r.rr'rrrr�r��s���95�01�%+�_�_�-.�%&�96!��L�L��e��,�97!��
"�
"�98!��,�,�s�E�z�*�	99!�100�
"�
"�101!�102�
103!�<�$4�<��<rr�c�8^�\rSrSrSrSSS\4U4SjjrSrU=r$)�wait_random_exponential��a�Random wait with exponentially widening window.104 105An exponential backoff strategy used to mediate contention between multiple106uncoordinated processes for a shared resource in distributed systems. This107is the sense in which "exponential backoff" is meant in e.g. Ethernet108networking, and corresponds to the "Full Jitter" algorithm described in109this blog post:110 111https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/112 113Each retry occurs at a random time in a geometrically expanding interval.114It allows for a custom multiplier and an ability to restrict the upper115limit of the random interval to some maximum value.116 117Example::118 119    wait_random_exponential(multiplier=0.5,  # initial window 0.5s120                            max=60)          # max 60s timeout121 122When waiting for an unavailable resource to become available again, as123opposed to trying to resolve contention for a shared resource, the124wait_exponential strategy (which uses a fixed interval) may be preferable.125 126rrr	c�`>�[TU]US9n[R"URU5$)NrV)r9rrH�uniformrA)rr�highr:s   �rr� wait_random_exponential.__call__�s*����w��K��8���~�~�d�h�h��-�-rr)	rrrr r!r$rr'r<r=s@rr�r��s!����2.�$4�.��.�.rr�c�h�\rSrSrSrS\RSS4S\S\S\S\S	S1274128SjjrSS
S	\4Sjr	Sr129g130)�wait_exponential_jitter��aHWait strategy that applies exponential backoff and jitter.131 132It allows for a customized initial wait, maximum wait and jitter.133 134This implements the strategy described here:135https://cloud.google.com/storage/docs/retry-strategy136 137The wait time is min(initial * 2**n + random.uniform(0, jitter), maximum)138where n is the retry count.139rJr��initialrBr��jitterr	Nc�4�XlX lX0lX@lgr)r�rBr�r�)rr�rBr�r�s     rr.� wait_exponential_jitter.__init__�s������ �
��rrrc��[R"SUR5nURURS-140-nUR141U-U-n[S[X@R55$![a URnN7f=f)NrrJ)	rHr�r�r�rer�r�rBrA)rrr�r�r�s     rr� wait_exponential_jitter.__call__142sy������4�;�;�/��	��-�-�K�$>�$>��$B�C�C��\�\�C�'�&�0�F��1�c�&�(�(�+�,�,���	��X�X�F�	�s�.A0�0B	�B	)r�r�r�rB)rrrr r!rr�r$r.rr'rrrr�r��sb��	���_�_���143��144��145��	146�147�148�149�
150�-�$4�-��-rr�)r"rHr%�tenacityr�
TYPE_CHECKINGr�ABCrr&rvr$r��	WaitBaseTr)r6r?rr_rkryr�r�r�rrr�<module>r�s���"�
�
��	���'�#����#�"
�L�L�
�v��� 0�1�6�<�<��s�151�3K�K�L�L�
�	�152����153��154�)�155�H�9�H�2��2�2$)�Y�$)�N-�	�-�,<�y�<�D.�.�.�>-�i�-r
codekingpro/portable-devtools · Team Ai