Your IP : 18.216.126.33


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

o

6��f���@s�	ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZdZe	jdkr~ed��dd�Zdd�ZGdd�dej�ZGdd�dej �Z!Gdd�dej"ej#�Z$Gdd�dej%�Z&Gdd�d�Z'Gdd �d e'�Z(Gd!d"�d"e'�Z)Gd#d$�d$e)�Z*Gd%d&�d&e)�Z+Gd'd(�d(e'�Z,Gd)d*�d*e'�Z-Gd+d,�d,ej.�Z/eZ0e/Z1dS)-�N�)�base_events)�base_subprocess)�	constants)�
coroutines)�events)�
exceptions)�futures)�selector_events)�tasks)�
transports)�logger)�SelectorEventLoop�AbstractChildWatcher�SafeChildWatcher�FastChildWatcher�PidfdChildWatcher�MultiLoopChildWatcher�ThreadedChildWatcher�DefaultEventLoopPolicyZwin32z+Signals are not really supported on WindowscCs	dS�N�)�signum�framerr�:/opt/alt/python310/lib64/python3.10/asyncio/unix_events.py�_sighandler_noop*srcCs$zt�|�WSty|YSwr)�os�waitstatus_to_exitcode�
ValueError)�statusrrrr/s
�rcs�eZdZ	d(�fdd�	Z�fdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z			d)dd�Z
		d)dd�Z	d(dd�Zdd�Z
	d(ddddd�dd�Z	d(dddddd�dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Z�ZS)*�_UnixSelectorEventLoopNcst��|�i|_dSr)�super�__init__�_signal_handlers)�self�selector��	__class__rrr"?�
z_UnixSelectorEventLoop.__init__cs`t���t��st|j�D]}|�|�qdS|jr.tjd|�d�t	|d�|j�
�dSdS)NzClosing the loop z@ on interpreter shutdown stage, skipping signal handlers removal��source)r!�close�sys�
is_finalizing�listr#�remove_signal_handler�warnings�warn�ResourceWarning�clear�r$�sigr&rrr+Cs
���z_UnixSelectorEventLoop.closecCs|D]
}|sq|�|�qdSr)�_handle_signal)r$�datarrrr�_process_self_dataQs
�z)_UnixSelectorEventLoop._process_self_datac
Gs0	t�|�st�|�rtd��|�|�|��z
t�|j�	��Wnt
tfy6}ztt
|���d}~wwt�|||d�}||j|<zt�|t�t�|d�WdSty�}z8|j|=|js�zt�d�Wnt
tfy�}zt�d|�WYd}~nd}~ww|jtjkr�td|�d����d}~ww)Nz3coroutines cannot be used with add_signal_handler()F����set_wakeup_fd(-1) failed: %s�sig � cannot be caught)rZiscoroutineZiscoroutinefunction�	TypeError�
_check_signalZ
_check_closed�signal�
set_wakeup_fdZ_csock�filenor�OSError�RuntimeError�strrZHandler#r�siginterruptr
�info�errno�EINVAL)r$r5�callback�args�exc�handleZnexcrrr�add_signal_handlerXs@
�
��
����z)_UnixSelectorEventLoop.add_signal_handlercCs<	|j�|�}|dur
dS|jr|�|�dS|�|�dSr)r#�getZ
_cancelledr/Z_add_callback_signalsafe)r$r5rLrrrr6�sz%_UnixSelectorEventLoop._handle_signalc
Cs�	|�|�z|j|=Wn
tyYdSw|tjkr tj}ntj}zt�||�WntyF}z|jtj	krAt
d|�d����d}~ww|jsnzt�d�WdSttfym}z
t
�d|�WYd}~dSd}~wwdS)NFr;r<r9r:T)r>r#�KeyErrorr?�SIGINT�default_int_handler�SIG_DFLrBrGrHrCr@rr
rF)r$r5�handlerrKrrrr/�s8
�
�����z,_UnixSelectorEventLoop.remove_signal_handlercCs8	t|t�s
td|����|t��vrtd|����dS)Nzsig must be an int, not zinvalid signal number )�
isinstance�intr=r?�
valid_signalsrr4rrrr>�s
�z$_UnixSelectorEventLoop._check_signalcC�t|||||�Sr)�_UnixReadPipeTransport�r$�pipe�protocol�waiter�extrarrr�_make_read_pipe_transport��z0_UnixSelectorEventLoop._make_read_pipe_transportcCrWr)�_UnixWritePipeTransportrYrrr�_make_write_pipe_transport�r_z1_UnixSelectorEventLoop._make_write_pipe_transportc	

�s��t���U}
|
��std��|��}t||||||||f||d�|	��}|
�|��|j|�z|IdHWnt	t
fy?�tyQ|��|�
�IdH�wWd�|S1s]wY|S)NzRasyncio.get_child_watcher() is not activated, subprocess support is not installed.)r\r])r�get_child_watcher�	is_activerC�
create_future�_UnixSubprocessTransport�add_child_handlerZget_pid�_child_watcher_callback�
SystemExit�KeyboardInterrupt�
BaseExceptionr+Z_wait)
r$r[rJ�shell�stdin�stdout�stderr�bufsizer]�kwargs�watcherr\�transprrr�_make_subprocess_transport�s:�

���
���
��z1_UnixSelectorEventLoop._make_subprocess_transportcCs|�|j|j|�dSr)�call_soon_threadsafe�	call_soonZ_process_exited)r$�pid�
returncoderrrrrrg�sz._UnixSelectorEventLoop._child_watcher_callback)�ssl�sock�server_hostname�ssl_handshake_timeoutc	�s�|r|durtd��n|durtd��|durtd��|durO|dur(td��t�|�}t�tjtjd�}z|�d�|�||�IdHWn(|���|durWtd��|j	tjksc|j
tjkrjtd|����|�d�|j|||||d	�IdH\}}||fS)
Nz/you have to pass server_hostname when using sslz+server_hostname is only meaningful with ssl�1ssl_handshake_timeout is only meaningful with ssl�3path and sock can not be specified at the same timerFzno path and sock were specified�.A UNIX Domain Stream Socket was expected, got )r{)rr�fspath�socket�AF_UNIX�SOCK_STREAM�setblockingZsock_connectr+�family�typeZ_create_connection_transport)	r$�protocol_factory�pathrxryrzr{�	transportr[rrr�create_unix_connection�sN�����

�
�z-_UnixSelectorEventLoop.create_unix_connection�dT)ry�backlogrxr{�
start_servingc
�s��t|t�r
td��|dur|std��|dur�|dur td��t�|�}t�tjtj�}|ddvrezt	�
t�	|�j�rBt�|�Wn!t
yLYntyd}z
t�d||�WYd}~nd}~wwz|�|�WnFty�}	z|��|	jtjkr�d|�d�}
ttj|
�d��d}	~	w|���|dur�td	��|jtjks�|jtjkr�td
|����|�d�t�||g||||�}|r�|��t�d�IdH|S)Nz*ssl argument must be an SSLContext or Noner|r}r)r�z2Unable to check or remove stale UNIX socket %r: %rzAddress z is already in usez-path was not specified, and no sock specifiedr~F)rT�boolr=rrrr�r�r��stat�S_ISSOCK�st_mode�remove�FileNotFoundErrorrBr
�errorZbindr+rGZ
EADDRINUSEr�r�r�rZServerZ_start_servingr�sleep)r$r�r�ryr�rxr{r��errrK�msgZserverrrr�create_unix_serversp�
��

�������
�z)_UnixSelectorEventLoop.create_unix_serverc

�s��ztjWntyt�d��wz|��}Wnttjfy-}zt�d��d}~wwzt�|�j	}Wnt
yBt�d��w|rG|n|}|sMdS|��}	|�|	d|||||d�|	IdHS)Nzos.sendfile() is not availableznot a regular filer)
r�sendfile�AttributeErrorr�SendfileNotAvailableErrorrA�io�UnsupportedOperation�fstat�st_sizerBrd�_sock_sendfile_native_impl)
r$ry�file�offset�countrAr�Zfsize�	blocksize�futrrr�_sock_sendfile_nativeUs6�
��
��
��
z,_UnixSelectorEventLoop._sock_sendfile_nativec	Cs*|��}	|dur
|�|�|��r|�|||�dS|r2||}|dkr2|�|||�|�|�dSz
t�|	|||�}
Wn�ttfya|durO|�	||�|�
|	|j||	||||||�
YdSty�}zK|dur�|j
t
jkr�t|�tur�tdt
j�}||_|}|dkr�t�d�}
|�|||�|�|
�n|�|||�|�|�WYd}~dSWYd}~dSd}~wttfy��ty�}z|�|||�|�|�WYd}~dSd}~ww|
dkr�|�|||�|�|�dS||
7}||
7}|du�r|�	||�|�
|	|j||	||||||�
dS)Nrzsocket is not connectedzos.sendfile call failed)rA�
remove_writer�	cancelled�_sock_sendfile_update_fileposZ
set_resultrr��BlockingIOError�InterruptedError�_sock_add_cancellation_callbackZ
add_writerr�rBrGZENOTCONNr��ConnectionError�	__cause__rr�Z
set_exceptionrhrirj)r$r�Z
registered_fdryrAr�r�r��
total_sent�fdZsentrK�new_excr�rrrr�lst


�������
�z1_UnixSelectorEventLoop._sock_sendfile_native_implcCs |dkrt�||tj�dSdS�Nr)r�lseek�SEEK_SET)r$rAr�r�rrrr��s�z4_UnixSelectorEventLoop._sock_sendfile_update_fileposcs��fdd�}|�|�dS)Ncs.|��r���}|dkr��|�dSdSdS)Nr9)r�rAr�)r�r��r$ryrr�cb�s�zB_UnixSelectorEventLoop._sock_add_cancellation_callback.<locals>.cb)Zadd_done_callback)r$r�ryr�rr�rr��sz6_UnixSelectorEventLoop._sock_add_cancellation_callbackr�NN)�__name__�
__module__�__qualname__r"r+r8rMr6r/r>r^rarsrgr�r�r�r�r�r��
__classcell__rrr&rr 9sD-
 
�
�
���.��CFr cs�eZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Ze
jfdd�Zddd�Zdd�Zdd�Z�ZS) rXiNcs�t��|�||jd<||_||_|��|_||_d|_d|_	t
�|j�j}t
�|�sBt
�|�sBt
�|�sBd|_d|_d|_td��t
�|jd�|j�|jj|�|j�|jj|j|j�|durm|j�tj|d�dSdS)NrZFz)Pipe transport is for pipes/sockets only.)r!r"�_extra�_loop�_piperA�_fileno�	_protocol�_closing�_pausedrr�r�r��S_ISFIFOr��S_ISCHRr�set_blockingru�connection_made�_add_reader�_read_readyr	�_set_result_unless_cancelled)r$�looprZr[r\r]�moder&rrr"�s8


���
��z_UnixReadPipeTransport.__init__cCs�|jjg}|jdur|�d�n|jr|�d�|�d|j���t|jdd�}|jdurH|durHt�	||jt
j�}|rB|�d�n|�d�n|jdurS|�d�n|�d�d�d	�
|��S)
N�closed�closing�fd=�	_selector�polling�idle�open�<{}>� )r'r�r��appendr�r��getattrr�r
�_test_selector_event�	selectorsZ
EVENT_READ�format�join)r$rFr%r�rrr�__repr__�s$



�

z_UnixReadPipeTransport.__repr__c
Cs�z
t�|j|j�}Wn$ttfyYdSty.}z
|�|d�WYd}~dSd}~ww|r9|j�	|�dS|j
��rDt�
d|�d|_|j
�|j�|j
�|jj�|j
�|jd�dS)Nz"Fatal read error on pipe transport�%r was closed by peerT)r�readr��max_sizer�r�rB�_fatal_errorr�Z
data_receivedr��	get_debugr
rFr��_remove_readerruZeof_received�_call_connection_lost)r$r7rKrrrr��s ��
z"_UnixReadPipeTransport._read_readycCsB|js|jrdSd|_|j�|j�|j��rt�d|�dSdS)NTz%r pauses reading)r�r�r�r�r�r�r
�debug�r$rrr�
pause_readings
�z$_UnixReadPipeTransport.pause_readingcCsF|js|jsdSd|_|j�|j|j�|j��r!t�d|�dSdS)NFz%r resumes reading)	r�r�r�r�r�r�r�r
r�r�rrr�resume_readings
�z%_UnixReadPipeTransport.resume_readingcC�
||_dSr�r��r$r[rrr�set_protocol�
z#_UnixReadPipeTransport.set_protocolcC�|jSrr�r�rrr�get_protocol�z#_UnixReadPipeTransport.get_protocolcCr�r�r�r�rrr�
is_closingr�z!_UnixReadPipeTransport.is_closingcCs|js
|�d�dSdSr)r��_closer�rrrr+!s�z_UnixReadPipeTransport.closecC�0|jdur|d|��t|d�|j��dSdS�Nzunclosed transport r)�r�r2r+�r$�_warnrrr�__del__%�
�z_UnixReadPipeTransport.__del__�Fatal error on pipe transportcCsZt|t�r|jtjkr|j��rtjd||dd�n|j�||||j	d��|�
|�dS�Nz%r: %sT��exc_info)�message�	exceptionr�r[)rTrBrGZEIOr�r�r
r��call_exception_handlerr�r��r$rKr�rrrr�*s
��z#_UnixReadPipeTransport._fatal_errorcCs(d|_|j�|j�|j�|j|�dS�NT)r�r�r�r�rur��r$rKrrrr�8sz_UnixReadPipeTransport._closecC�Nz|j�|�W|j��d|_d|_d|_dS|j��d|_d|_d|_wr�r�Zconnection_lostr�r+r�rrrrr�=�


�z,_UnixReadPipeTransport._call_connection_lostr��r�)r�r�r�r�r"r�r�r�r�r�r�r�r+r0r1r�r�r�r�r�rrr&rrX�s
rXcs�eZdZd%�fdd�	Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zejfdd�Zdd�Zd&dd �Zd'd!d"�Zd#d$�Z�ZS)(r`Nc
st��||�||jd<||_|��|_||_t�|_d|_	d|_
t�|j�j
}t�|�}t�|�}t�|�}	|sJ|sJ|	sJd|_d|_d|_td��t�|jd�|j�|jj|�|	sd|rptj�d�sp|j�|jj|j|j�|dur|j�tj|d�dSdS)NrZrFz?Pipe transport is only for pipes, sockets and character devices�aix)r!r"r�r�rAr�r��	bytearray�_buffer�
_conn_lostr�rr�r�r�r�r�r�rr�r�rur�r,�platform�
startswithr�r�r	r�)
r$r�rZr[r\r]r�Zis_charZis_fifoZ	is_socketr&rrr"Js8




�
��z _UnixWritePipeTransport.__init__cCs�|jjg}|jdur|�d�n|jr|�d�|�d|j���t|jdd�}|jdurT|durTt�	||jt
j�}|rB|�d�n|�d�|��}|�d|���n|jdur_|�d�n|�d�d	�
d
�|��S)Nr�r�r�r�r�r�zbufsize=r�r�r�)r'r�r�r�r�r�r�r�r
r�r�ZEVENT_WRITE�get_write_buffer_sizer�r�)r$rFr%r�rorrrr�os(



�


z _UnixWritePipeTransport.__repr__cCs
t|j�Sr)�lenr	r�rrrr
�r�z-_UnixWritePipeTransport.get_write_buffer_sizecCs8|j��rt�d|�|jr|�t��dS|��dS)Nr�)r�r�r
rFr	r��BrokenPipeErrorr�rrrr��s

z#_UnixWritePipeTransport._read_readyc
Cs&t|t�r	t|�}|s
dS|js|jr'|jtjkrt�d�|jd7_dS|j	s�z	t
�|j|�}Wn5t
tfy@d}Yn)ttfyI�tyh}z|jd7_|�|d�WYd}~dSd}~ww|t|�krqdS|dkr}t|�|d�}|j�|j|j�|j	|7_	|��dS)Nz=pipe closed by peer or os.write(pipe, data) raised exception.rr�#Fatal write error on pipe transport)rTr�
memoryviewr
r�rZ!LOG_THRESHOLD_FOR_CONNLOST_WRITESr
�warningr	r�writer�r�r�rhrirjr�rr�Z_add_writer�_write_readyZ_maybe_pause_protocol)r$r7�nrKrrrr�s:

��z_UnixWritePipeTransport.writec
Csz
t�|j|j�}Wn@ttfyYdSttfy�tyJ}z |j�	�|j
d7_
|j�|j�|�
|d�WYd}~dSd}~ww|t|j�krs|j�	�|j�|j�|��|jrq|j�|j�|�d�dS|dkr|jd|�=dSdS)Nrrr)rrr�r	r�r�rhrirjr3r
r��_remove_writerr�rZ_maybe_resume_protocolr�r�r�)r$rrKrrrr�s0
��

�z$_UnixWritePipeTransport._write_readycC�dSrrr�rrr�
can_write_eof��z%_UnixWritePipeTransport.can_write_eofcCs<|jrdSd|_|js|j�|j�|j�|jd�dSdSr)r�r	r�r�r�rur�r�rrr�	write_eof�s�z!_UnixWritePipeTransport.write_eofcCr�rr�r�rrrr��r�z$_UnixWritePipeTransport.set_protocolcCr�rr�r�rrrr��r�z$_UnixWritePipeTransport.get_protocolcCr�rr�r�rrrr��r�z"_UnixWritePipeTransport.is_closingcCs$|jdur|js|��dSdSdSr)r�r�rr�rrrr+�s�z_UnixWritePipeTransport.closecCr�r�r�r�rrrr��r�z_UnixWritePipeTransport.__del__cC�|�d�dSr)r�r�rrr�abort��z_UnixWritePipeTransport.abortr�cCsNt|t�r|j��rtjd||dd�n|j�||||jd��|�|�dSr�)	rTrBr�r�r
r�r�r�r�rrrrr��s

��z$_UnixWritePipeTransport._fatal_errorcCsFd|_|jr
|j�|j�|j��|j�|j�|j�|j|�dSr)	r�r	r�rr�r3r�rur�rrrrr�s
z_UnixWritePipeTransport._closecCrrrrrrrr�
rz-_UnixWritePipeTransport._call_connection_lostr�rr)r�r�r�r"r�r
r�rrrrr�r�r�r+r0r1r�rr�r�r�r�rrr&rr`Gs$%	#	

r`c@seZdZdd�ZdS)rec		Ks�d}|tjkrtj�d�rt��\}}z7tj|f||||d|d�|��|_|dur:|�	�t
|��d|d�|j_d}W|durI|�	�|�	�dSdS|durX|�	�|�	�ww)NrF)rkrlrmrnZuniversal_newlinesro�wb)�	buffering)
�
subprocess�PIPEr,rrr�Z
socketpair�Popen�_procr+r��detachrl)	r$rJrkrlrmrnrorpZstdin_wrrr�_starts0�����
�z_UnixSubprocessTransport._startN)r�r�r�r%rrrrresrec@sFeZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)rcG�	t��r��NotImplementedError�r$rvrIrJrrrrfCsz&AbstractChildWatcher.add_child_handlercCr&rr'�r$rvrrr�remove_child_handlerNsz)AbstractChildWatcher.remove_child_handlercCr&rr'�r$r�rrr�attach_loopVsz AbstractChildWatcher.attach_loopcCr&rr'r�rrrr+`szAbstractChildWatcher.closecCr&rr'r�rrrrcgszAbstractChildWatcher.is_activecCr&rr'r�rrr�	__enter__pszAbstractChildWatcher.__enter__cCr&rr'�r$�a�b�crrr�__exit__vszAbstractChildWatcher.__exit__N)
r�r�r�rfr+r-r+rcr.r3rrrrr,s
	rc@sVeZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)rcC�d|_i|_dSr�r��
_callbacksr�rrrr"��
zPidfdChildWatcher.__init__cC�|Srrr�rrrr.�rzPidfdChildWatcher.__enter__cC�dSrr)r$�exc_type�	exc_value�
exc_tracebackrrrr3�rzPidfdChildWatcher.__exit__cC�|jduo	|j��Sr�r�Z
is_runningr�rrrrc��zPidfdChildWatcher.is_activecCrr�r-r�rrrr+�rzPidfdChildWatcher.closecCsd|jdur|dur|jrt�dt�|j��D]\}}}|j�|�t�|�q|j�	�||_dS�NzCA loop is being detached from a child watcher with pending handlers)
r�r6r0r1�RuntimeWarning�valuesr�rr+r3)r$r��pidfd�_rrrr-�s�

zPidfdChildWatcher.attach_loopcGs\|j�|�}|dur|d||f|j|<dSt�|�}|j�||j|�|||f|j|<dSr�)r6rNrZ
pidfd_openr�r��_do_wait)r$rvrIrJZexistingrDrrrrf�s
z#PidfdChildWatcher.add_child_handlercCs~|j�|�\}}}|j�|�z
t�|d�\}}Wnty*d}t�d|�Ynwt	|�}t�
|�|||g|�R�dS)Nr�zJchild process pid %d exit status already read:  will report returncode 255)r6�popr�r�r�waitpid�ChildProcessErrorr
rrr+)r$rvrDrIrJrErrwrrrrF�s��	
zPidfdChildWatcher._do_waitcCsFz|j�|�\}}}Wn
tyYdSw|j�|�t�|�dS)NFT)r6rHrOr�r�rr+)r$rvrDrErrrr+�s�
z&PidfdChildWatcher.remove_child_handlerN)r�r�r�r"r.r3rcr+r-rfrFr+rrrrr{s	rc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�BaseChildWatchercCr4rr5r�rrrr"�r7zBaseChildWatcher.__init__cCrrr@r�rrrr+�rzBaseChildWatcher.closecCr=rr>r�rrrrc�r?zBaseChildWatcher.is_activecC�t��rr')r$�expected_pidrrr�_do_waitpid�r�zBaseChildWatcher._do_waitpidcCrLrr'r�rrr�_do_waitpid_all�r�z BaseChildWatcher._do_waitpid_allcCsj|jdur|dur|jrt�dt�|jdur|j�tj�||_|dur3|�tj|j	�|�
�dSdSrA)r�r6r0r1rBr/r?�SIGCHLDrM�	_sig_chldrOr,rrrr-�s�
�zBaseChildWatcher.attach_loopc
CsZz|��WdSttfy�ty,}z|j�d|d��WYd}~dSd}~ww)N�$Unknown exception in SIGCHLD handler)r�r�)rOrhrirjr�r�rrrrrQ�s���zBaseChildWatcher._sig_chldN)
r�r�r�r"r+rcrNrOr-rQrrrrrK�srKcsNeZdZ	�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)rcs|j��t���dSr)r6r3r!r+r�r&rrr+	s
zSafeChildWatcher.closecCr8rrr�rrrr.
rzSafeChildWatcher.__enter__cCr9rrr/rrrr3rzSafeChildWatcher.__exit__cGs||f|j|<|�|�dSr)r6rNr)rrrrfsz"SafeChildWatcher.add_child_handlercC�$z|j|=WdStyYdSw�NTF�r6rOr*rrrr+��z%SafeChildWatcher.remove_child_handlercC�t|j�D]}|�|�qdSr�r.r6rNr*rrrrO s�z SafeChildWatcher._do_waitpid_allcCs�zt�|tj�\}}Wnty|}d}t�d|�Ynw|dkr%dSt|�}|j��r5t�	d||�z
|j
�|�\}}WntyY|j��rVtjd|dd�YdSYdSw|||g|�R�dS)NrG�8Unknown child process pid %d, will report returncode 255r�$process %s exited with returncode %s�'Child watcher got an unexpected pid: %rTr�)
rrI�WNOHANGrJr
rrr�r�r�r6rHrO)r$rMrvrrwrIrJrrrrN%s6��	
�
���zSafeChildWatcher._do_waitpid)r�r�r�r+r.r3rfr+rOrNr�rrr&rr�s
rcsReZdZ	�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)rcs$t���t��|_i|_d|_dSr�)r!r"�	threadingZLock�_lock�_zombies�_forksr�r&rrr"Rs


zFastChildWatcher.__init__cs"|j��|j��t���dSr)r6r3r_r!r+r�r&rrr+Xs

zFastChildWatcher.closecCs<|j�|jd7_|Wd�S1swYdS)Nr)r^r`r�rrrr.]s$�zFastChildWatcher.__enter__cCsv|j�(|jd8_|js|js	Wd�dSt|j�}|j��Wd�n1s.wYt�d|�dS)Nrz5Caught subprocesses termination from unknown pids: %s)r^r`r_rDr3r
r)r$r0r1r2Zcollateral_victimsrrrr3cs�
�	�zFastChildWatcher.__exit__c	Gs||j�(z|j�|�}Wnty#||f|j|<YWd�dSwWd�n1s.wY|||g|�R�dSr)r^r_rHrOr6)r$rvrIrJrwrrrrfqs���	z"FastChildWatcher.add_child_handlercCrSrTrUr*rrrr+rVz%FastChildWatcher.remove_child_handlerc	Cs	zt�dtj�\}}Wn
tyYdSw|dkrdSt|�}|j�Fz
|j�|�\}}Wn'tyV|j	rR||j
|<|j��rJt
�d||�YWd�qd}Yn
w|j��rct
�d||�Wd�n1smwY|dur~t
�d||�n	|||g|�R�q)NTr9rz,unknown process %s exited with returncode %srZz8Caught subprocess termination from unknown pid: %d -> %d)rrIr\rJrr^r6rHrOr`r_r�r�r
r�r)r$rvrrwrIrJrrrrO�sH�

��
�
�����z FastChildWatcher._do_waitpid_all)r�r�r�r"r+r.r3rfr+rOr�rrr&rrHs	rc@sfeZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)rcCsi|_d|_dSr)r6�_saved_sighandlerr�rrrr"�r7zMultiLoopChildWatcher.__init__cCs
|jduSr)rar�rrrrc�r�zMultiLoopChildWatcher.is_activecCsT|j��|jdurdSt�tj�}||jkrt�d�nt�tj|j�d|_dS)Nz+SIGCHLD handler was changed by outside code)	r6r3rar?�	getsignalrPrQr
r)r$rSrrrr+�s



zMultiLoopChildWatcher.closecCr8rrr�rrrr.�rzMultiLoopChildWatcher.__enter__cCr9rr�r$r:Zexc_valZexc_tbrrrr3�rzMultiLoopChildWatcher.__exit__cGs&t��}|||f|j|<|�|�dSr)r�get_running_loopr6rN)r$rvrIrJr�rrrrf�sz'MultiLoopChildWatcher.add_child_handlercCrSrTrUr*rrrr+�rVz*MultiLoopChildWatcher.remove_child_handlercCsN|jdurdSt�tj|j�|_|jdurt�d�tj|_t�tjd�dS)NzaPrevious SIGCHLD handler was set by non-Python code, restore to default handler on watcher close.F)rar?rPrQr
rrRrEr,rrrr-�s


z!MultiLoopChildWatcher.attach_loopcCrWrrXr*rrrrO�s�z%MultiLoopChildWatcher._do_waitpid_allc	Cs�zt�|tj�\}}Wnty |}d}t�d|�d}Yn
w|dkr'dSt|�}d}z|j�|�\}}}Wnt	yJtjd|dd�YdSw|�
�rXt�d||�dS|re|��ret�d	||�|j
|||g|�R�dS)
NrGrYFrTr[r��%Loop %r that handles pid %r is closedrZ)rrIr\rJr
rrr6rHrO�	is_closedr�r�rt)	r$rMrvrrwZ	debug_logr�rIrJrrrrNs:��
���z!MultiLoopChildWatcher._do_waitpidc	CsDz|��WdSttfy�ty!tjddd�YdSw)NrRTr�)rOrhrirjr
r)r$rrrrrrQ%s�zMultiLoopChildWatcher._sig_chldN)r�r�r�r"rcr+r.r3rfr+r-rOrNrQrrrrr�s%rc@sleZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	j
fd
d�Zdd�Zdd�Z
dd�Zdd�ZdS)rcCst�d�|_i|_dSr�)�	itertoolsr��_pid_counter�_threadsr�rrrr";r(zThreadedChildWatcher.__init__cCrrrr�rrrrc?rzThreadedChildWatcher.is_activecCs|��dSr)�
_join_threadsr�rrrr+BszThreadedChildWatcher.closecCs0	dd�t|j���D�}|D]}|��qdS)NcSsg|]}|��r|js|�qSr)�is_alive�daemon��.0�threadrrr�
<listcomp>Gs
�
�z6ThreadedChildWatcher._join_threads.<locals>.<listcomp>)r.rirCr�)r$�threadsrorrrrjEs

�z"ThreadedChildWatcher._join_threadscCr8rrr�rrrr.LrzThreadedChildWatcher.__enter__cCr9rrrcrrrr3OrzThreadedChildWatcher.__exit__cCs:dd�t|j���D�}|r||j�d�t|d�dSdS)NcSsg|]}|��r|�qSr)rkrmrrrrpSs
�z0ThreadedChildWatcher.__del__.<locals>.<listcomp>z0 has registered but not finished child processesr))r.rirCr'r2)r$r�rqrrrr�Rs
��zThreadedChildWatcher.__del__cGsFt��}tj|jdt|j���||||fdd�}||j|<|��dS)Nzwaitpid-T)�target�namerJrl)	rrdr]ZThreadrN�nextrhri�start)r$rvrIrJr�rorrrrfZs
�
z&ThreadedChildWatcher.add_child_handlercCrrrr*rrrr+csz)ThreadedChildWatcher.remove_child_handlercCr9rrr,rrrr-irz ThreadedChildWatcher.attach_loopcCs�z
t�|d�\}}Wnty|}d}t�d|�Ynwt|�}|��r-t�d||�|��r9t�d||�n|j	|||g|�R�|j
�|�dS)NrrGrYrZre)rrIrJr
rrr�r�rfrtrirH)r$r�rMrIrJrvrrwrrrrNls&��	�z ThreadedChildWatcher._do_waitpidN)r�r�r�r"rcr+rjr.r3r0r1r�rfr+r-rNrrrrr.s	rcsFeZdZ	eZ�fdd�Zdd�Z�fdd�Zdd�Zd	d
�Z	�Z
S)�_UnixDefaultEventLoopPolicycst���d|_dSr)r!r"�_watcherr�r&rrr"�s

z$_UnixDefaultEventLoopPolicy.__init__cCs~tj�2|jdur%t�|_t��t��ur-|j�|jj	�Wd�dSWd�dSWd�dS1s8wYdSr)
rr^rwrr]�current_thread�main_threadr-�_localr�r�rrr�
_init_watcher�s
��"�z)_UnixDefaultEventLoopPolicy._init_watchercs@	t��|�|jdurt��t��ur|j�|�dSdSdSr)r!�set_event_looprwr]rxryr-r,r&rrr|�s
�z*_UnixDefaultEventLoopPolicy.set_event_loopcCs	|jdur
|��|jSr)rwr{r�rrrrb�s
z-_UnixDefaultEventLoopPolicy.get_child_watchercCs 	|jdur|j��||_dSr)rwr+)r$rqrrr�set_child_watcher�s


z-_UnixDefaultEventLoopPolicy.set_child_watcher)r�r�r�r Z
_loop_factoryr"r{r|rbr}r�rrr&rrv�s
rv)2rGr�rgrr�r?r�r�r r,r]r0�rrrrrrr	r
rr�logr
�__all__r�ImportErrorrrZBaseSelectorEventLoopr Z
ReadTransportrXZ_FlowControlMixinZWriteTransportr`ZBaseSubprocessTransportrerrrKrrrrZBaseDefaultEventLoopPolicyrvrrrrrr�<module>sd
	
		�NON5Ji}Y2

?>