Your IP : 3.139.69.138


Current Path : /opt/alt/python310/lib64/python3.10/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/asyncio/__pycache__/tasks.cpython-310.opt-2.pyc

o

6��f�~�@sj	dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddlm
Z
ddlmZddlm
Z
ddlmZddlmZdd	lmZdd
l
mZe�d�jZdBdd�ZdBd
d�Zdd�ZGdd�dej�ZeZzddlZWn	ey{YnwejZZdd�dd�ZejjZejj Z ejj!Z!de!d�dd�Z"dd�Z#dd�Z$dd�Z%dd �Z&dd!�d"d#�Z'ej(d$d%��Z)dBd&d'�Z*dd(�d)d*�Z+dd(�d+d,�Z,ej(d-d.��Z-ee-_Gd/d0�d0ej.�Z/d1d2�d3d4�Z0d5d6�Z1d7d8�Z2e	�3�Z4iZ5d9d:�Z6d;d<�Z7d=d>�Z8d?d@�Z9e6Z:e9Z;e7Z<e8Z=zddAlm6Z6m9Z9m7Z7m8Z8m4Z4m5Z5Wne�y*YdSwe6Z>e9Z?e7Z@e8ZAdS)C)�Task�create_task�FIRST_COMPLETED�FIRST_EXCEPTION�
ALL_COMPLETED�wait�wait_for�as_completed�sleep�gather�shield�
ensure_future�run_coroutine_threadsafe�current_task�	all_tasks�_register_task�_unregister_task�_enter_task�_leave_task�N)�GenericAlias�)�
base_tasks)�
coroutines)�events)�
exceptions)�futures)�
_is_coroutinecCs	|dur	t��}t�|�S�N)r�get_running_loop�_current_tasks�get��loop�r#�4/opt/alt/python310/lib64/python3.10/asyncio/tasks.pyr#s
rcs`	�dur	t���d}	ztt�}Wnty$|d7}|dkr"�Ynwnq�fdd�|D�S)NrTri�cs&h|]}t�|��ur|��s|�qSr#)r�	_get_loop�done)�.0�tr!r#r$�	<setcomp>=s�zall_tasks.<locals>.<setcomp>)rr�list�
_all_tasks�RuntimeError)r"�iZtasksr#r!r$r*s ���	rcCs8|durz|j}Wn
tyYdSw||�dSdSr)�set_name�AttributeError)�task�namer.r#r#r$�_set_task_nameAs
��r2cs�eZdZ	dZddd��fdd�
Z�fdd�Zee�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�dd�Zddd�dd�Zd dd�Zd �fdd�	Zdd�Z�ZS)!rTN)r"r1cs�t�j|d�|jr|jd=t�|�sd|_td|����|dur)dt���|_nt	|�|_d|_
d|_||_t
��|_|jj|j|jd�t|�dS)Nr!���Fza coroutine was expected, got zTask-��context)�super�__init__�_source_tracebackr�iscoroutine�_log_destroy_pending�	TypeError�_task_name_counter�_name�str�_must_cancel�_fut_waiter�_coro�contextvarsZcopy_context�_context�_loop�	call_soon�_Task__stepr)�self�coror"r1��	__class__r#r$r7]s


z
Task.__init__csF|jtjkr|jr|dd�}|jr|j|d<|j�|�t���dS)Nz%Task was destroyed but it is pending!)r0�messageZsource_traceback)	Z_staterZ_PENDINGr:r8rDZcall_exception_handlerr6�__del__)rGr5rIr#r$rLts�
zTask.__del__cCs
t�|�Sr)rZ_task_repr_info�rGr#r#r$�
_repr_info�s
zTask._repr_infocC�|jSr)rArMr#r#r$�get_coro��z
Task.get_corocCrOr)r=rMr#r#r$�get_name�rQz
Task.get_namecCst|�|_dSr)r>r=)rG�valuer#r#r$r.�sz
Task.set_namecC�td��)Nz*Task does not support set_result operation�r,)rG�resultr#r#r$�
set_result��zTask.set_resultcCrT)Nz-Task does not support set_exception operationrU)rG�	exceptionr#r#r$�
set_exception�rXzTask.set_exception)�limitcCs	t�||�Sr)rZ_task_get_stack)rGr[r#r#r$�	get_stack�szTask.get_stack)r[�filecCs	t�|||�Sr)rZ_task_print_stack)rGr[r]r#r#r$�print_stack�szTask.print_stackcCs@	d|_|��r
dS|jdur|jj|d�rdSd|_||_dS�NF��msgT)Z_log_tracebackr&r@�cancelr?�_cancel_message)rGrar#r#r$rb�s
zTask.cancelc
s�|��rt�d|�d|����|jrt|tj�s|��}d|_|j}d|_t	|j
|��z�z|dur8|�d�}n|�|�}Wnnt
yg}z|jrUd|_t�j|jd�nt��|j�WYd}~�n
d}~wtjy�}z||_t���WYd}~n�d}~wttfy�}zt��|��d}~wty�}zt��|�WYd}~n�d}~wwt|dd�}|du�r't�|�|j
ur�td|�d|�d��}|j
j|j||jd	�n�|�r||ur�td
|���}|j
j|j||jd	�n�d|_|j |j!|jd	�||_|j�r|jj|jd��rd|_n�td|�d|���}|j
j|j||jd	�nj|du�r7|j
j|j|jd	�n�t"�#|��rStd
|�d|���}|j
j|j||jd	�nutd|���}|j
j|j||jd	�Wt$|j
|�d}dSWt$|j
|�d}dSWt$|j
|�d}dSWt$|j
|�d}dSWt$|j
|�d}dSWt$|j
|�d}dSWt$|j
|�d}dSWt$|j
|�d}dSWt$|j
|�d}dSWt$|j
|�d}dSt$|j
|�d}w)Nz_step(): already done: z, Fr`�_asyncio_future_blockingzTask z got Future z attached to a different loopr4zTask cannot await on itself: z-yield was used instead of yield from in task z with z;yield was used instead of yield from for generator in task zTask got bad yield: )%r&rZInvalidStateErrorr?�
isinstance�CancelledError�_make_cancelled_errorrAr@rrD�send�throw�
StopIterationr6rbrcrWrSZ_cancelled_exc�KeyboardInterrupt�
SystemExitrZ�
BaseException�getattrrr%r,rErFrCrd�add_done_callback�
_Task__wakeup�inspectZisgeneratorr)rG�excrHrVZblocking�new_excrIr#r$Z__step�s��
������
��
��
�������
�
���
�
����6�1��(���"���zTask.__stepc
CsRz|��Wnty }z|�|�WYd}~d}dSd}~ww|��d}dSr)rVrmrF)rG�futurerrr#r#r$Z__wakeup.s	��
z
Task.__wakeupr)�__name__�
__module__�__qualname__r:r7rL�classmethodr�__class_getitem__rNrPrRr.rWrZr\r^rbrFrp�
__classcell__r#r#rIr$rKs"

"Wr)r1cCs"	t��}|�|�}t||�|Sr)rrrr2)rHr1r"r0r#r#r$rKs


r)�timeout�return_whenc�s��	t�|�st�|�rtdt|�j����|std��|tt	t
fvr*td|����t���t
|�}tdd�|D��rCtjdtdd��fd	d
�|D�}t|||��IdHS)Nzexpect a list of futures, not z#Set of coroutines/Futures is empty.zInvalid return_when value: css�|]}t�|�VqdSr)rr9�r'�fr#r#r$�	<genexpr>xs�zwait.<locals>.<genexpr>z�The explicit passing of coroutine objects to asyncio.wait() is deprecated since Python 3.8, and scheduled for removal in Python 3.11.���
stacklevelc�h|]}t|�d��qS�r!�rr}r!r#r$r)~�zwait.<locals>.<setcomp>)r�isfuturerr9r;�typeru�
ValueErrorrrrrr�set�any�warnings�warn�DeprecationWarning�_wait)�fsr{r|r#r!r$r]s ��rcGs|��s|�d�dSdSr)r&rW)�waiter�argsr#r#r$�_release_waiter���r�c
�s��	t��}|dur|IdHS|dkrBt||d�}|��r!|��St||d�IdHz|��WStjyA}zt��|�d}~ww|�	�}|�
|t|�}t�
t|�}t||d�}|�|�zfz|IdHWn&tjy�|��r}|��YW|��S|�|�t||d�IdH�w|��r�|��W|��S|�|�t||d�IdHz
|��WW|��Stjy�}zt��|�d}~ww|��w)Nrr!)rrrr&rV�_cancel_and_waitrrf�TimeoutError�
create_future�
call_laterr��	functools�partialrorb�remove_done_callback)�futr{r"rrr��timeout_handle�cbr#r#r$r�sZ�


��


��

�

�
��
rc
�s��	|���d�|dur|�|t���t|������fdd�}|D]}|�|�q"z�IdHW�dur9���|D]}|�|�q;n�durL���|D]}|�|�qNwt�t�}}|D]}|��rl|�	|�q`|�	|�q`||fS)Ncsj�d8��dks�tks�tkr-|��s/|��dur1�dur"������s3��d�dSdSdSdSdS)Nrr)rr�	cancelledrYrbr&rW�r~�Zcounterr|r�r�r#r$�_on_completion�s�z_wait.<locals>._on_completion)
r�r�r��lenrorbr�r�r&�add)r�r{r|r"r�r~r&Zpendingr#r�r$r��s8����r�c	�sR�	|��}t�t|�}|�|�z|��|IdHW|�|�dS|�|�wr)r�r�r�r�rorbr�)r�r"r�r�r#r#r$r��s�
r�)r{c#s��	t�|�st�|�rtdt|�j����ddlm}|��t	�
���fdd�t|�D��d����fdd�}���fdd	���fd
d�}�D]}|���qH�r\|dur\��
||��tt���D]}|�VqbdS)Nz#expect an iterable of futures, not r)�Queuecr�r�r�r}r!r#r$r)%r�zas_completed.<locals>.<setcomp>cs*�D]}|�����d�q���dSr)r��
put_nowait�clearr�)r�r&�todor#r$�_on_timeout(s
z!as_completed.<locals>._on_timeoutcs<�sdS��|���|��s�dur���dSdSdSr)�remover�rbr�)r&r�r�r#r$r�.s

�z$as_completed.<locals>._on_completionc�s&����IdH}|durtj�|��Sr)r rr�rVr�)r&r#r$�
_wait_for_one6s
�z#as_completed.<locals>._wait_for_one)rr�rr9r;r�ruZqueuesr�r�_get_event_loopr�ror��ranger�)r�r{r�r�r�r~�_r#)r�r&r"r�r�r$rs&�
�rccs�	dVdSrr#r#r#r#r$�__sleep0Es�
r�c�s^�	|dkrt�IdH|St��}|��}|�|tj||�}z
|IdHW|��S|��w)Nr)r�rrr�r�rZ_set_result_unless_cancelledrb)ZdelayrVr"rt�hr#r#r$r	Qs��
r	r!cCs	t||d�S�Nr!)�_ensure_future)�coro_or_futurer"r#r#r$rbsrcCs�t�|�r|dur|t�|�urtd��|Sd}t�|�s-t�|�r)t|�}d}nt	d��|dur7t
jdd�}z|�|�WSt
yK|sJ|���w)NzRThe future belongs to a different loop than the one specified as the loop argumentFTz:An asyncio.Future, a coroutine or an awaitable is required�r�)rr�r%r�rr9rqZisawaitable�_wrap_awaitabler;rr�rr,�close)r�r"Zcalled_wrap_awaitabler#r#r$r�js&


�r�ccs�	|��EdHSr)�	__await__)Z	awaitabler#r#r$r��s�r�cs(eZdZ	�fdd�Zddd�Z�ZS)�_GatheringFuturecst�j|d�||_d|_dS)Nr!F)r6r7�	_children�_cancel_requested)rG�childrenr"rIr#r$r7�s
z_GatheringFuture.__init__NcCs:|��rdSd}|jD]
}|j|d�rd}q|rd|_|Sr_)r&r�rbr�)rGraZret�childr#r#r$rb�s
�z_GatheringFuture.cancelr)rurvrwr7rbrzr#r#rIr$r��sr�F)�return_exceptionscs�	|st��}|�����g��S�����fdd�}i}g�d�d�d}d�|D]3}||vrTt||d�}|dur?t�|�}||urFd|_�d7�|||<|�|�n||}��	|�q*t
�|d���S)Ncs��d7��dus���r|��s|��dS�s6|��r'|��}��|�dS|��}|dur6��|�dS��kryg}�D]%}|��rRt�|jdurMdn|j�}n|��}|dur^|��}|�	|�q>�j
rr|��}��|�dS��|�dSdS)Nr�)r&r�rYrgrZrrfrcrV�appendr�rW)r�rrZresults�res�r�Z	nfinishedZnfuts�outerr�r#r$�_done_callback�s>

��zgather.<locals>._done_callbackrr!Fr)rr�r�rWr�rr%r:ror�r�)r�Zcoros_or_futuresr"r�Z
arg_to_fut�argr�r#r�r$r
�s6
7
r
csZ	t|�����r�St���}|����fdd����fdd�}������|��S)Ncs`���r|��s|��dS|��r���dS|��}|dur'��|�dS��|���dSr)r�rYrbrZrWrV)�innerrr�r�r#r$�_inner_done_callbackOsz$shield.<locals>._inner_done_callbackcs���s����dSdSr)r&r�r�)r�r�r#r$�_outer_done_callback`r�z$shield.<locals>._outer_done_callback)r�r&rr%r�ro)r�r"r�r#)r�r�r�r$r's 


rcs<	t���s
td��tj������fdd�}��|��S)NzA coroutine object is requiredc
sZz
t�t��d���WdSttfy�ty,}z
���r'��|��d}~wwr�)rZ
_chain_futurerrlrkrmZset_running_or_notify_cancelrZ)rr�rHrtr"r#r$�callbackrs
��z*run_coroutine_threadsafe.<locals>.callback)rr9r;�
concurrentr�FutureZcall_soon_threadsafe)rHr"r�r#r�r$r
is



r
cC�	t�|�dSr)r+r��r0r#r#r$r��rcCs4t�|�}|durtd|�d|�d���|t|<dS)NzCannot enter into task z while another task z is being executed.�rr r,�r"r0rr#r#r$r�s


�rcCs2t�|�}||urtd|�d|�d���t|=dS)Nz
Leaving task z! does not match the current task �.r�r�r#r#r$r�s


�
rcCr�r)r+�discardr�r#r#r$r�r�r)rrrrr+rr)B�__all__Zconcurrent.futuresr�rBr�rq�	itertools�typesr��weakrefrr�rrrrrr�count�__next__r<rrr2Z	_PyFuturerZ_PyTaskZ_asyncio�ImportErrorZ_CTaskrrrrrr�rr�r�r�	coroutiner�r	rr�r�r�r�r
rr
ZWeakSetr+rrrrrZ_py_register_taskZ_py_unregister_taskZ_py_enter_taskZ_py_leave_taskZ_c_register_taskZ_c_unregister_taskZ
_c_enter_taskZ
_c_leave_taskr#r#r#r$�<module>s�	


u�

&G,9


{B$�

?>