Hacked By AnonymousFox

Current Path : /opt/alt/python37/lib64/python3.7/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/asyncio/__pycache__/unix_events.cpython-37.pyc

B

� f؟�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZdZe	jdkr�ed��dd�ZGdd�dej�ZGdd�dej�ZGdd�dej ej!�Z"Gdd�dej#�Z$Gdd�d�Z%Gdd�de%�Z&Gdd �d e&�Z'Gd!d"�d"e&�Z(Gd#d$�d$ej)�Z*eZ+e*Z,dS)%z2Selector event loop for Unix with signal handling.�N�)�base_events)�base_subprocess)�	constants)�
coroutines)�events)�futures)�selector_events)�tasks)�
transports)�logger)�SelectorEventLoop�AbstractChildWatcher�SafeChildWatcher�FastChildWatcher�DefaultEventLoopPolicyZwin32z+Signals are not really supported on WindowscCsdS)zDummy signal handler.N�)�signum�framerr�8/opt/alt/python37/lib64/python3.7/asyncio/unix_events.py�_sighandler_noop'srcs�eZdZdZd)�fdd�	Z�fdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
d*dd�Zd+dd�Zd,dd�Z
dd�Zd-ddddd�dd�Zd.dddddd�dd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Z�ZS)/�_UnixSelectorEventLoopzdUnix event loop.

    Adds signal handling and UNIX Domain Socket support to SelectorEventLoop.
    Ncst��|�i|_dS)N)�super�__init__�_signal_handlers)�self�selector)�	__class__rrr2sz_UnixSelectorEventLoop.__init__cs^t���t��s2xFt|j�D]}|�|�qWn(|jrZtjd|�d�t	|d�|j�
�dS)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�sig)rrrr6s
z_UnixSelectorEventLoop.closecCs"x|D]}|sq|�|�qWdS)N)�_handle_signal)r�datarrrr�_process_self_dataDs
z)_UnixSelectorEventLoop._process_self_datac
GsLt�|�st�|�rtd��|�|�|��yt�|j�	��Wn2t
tfk
rt}ztt
|���Wdd}~XYnXt�|||d�}||j|<yt�|t�t�|d�Wn�tk
�rF}zz|j|=|j�syt�d�Wn4t
tfk
�r}zt�d|�Wdd}~XYnX|jtjk�r4td|�d���n�Wdd}~XYnXdS)z�Add a handler for a signal.  UNIX only.

        Raise ValueError if the signal number is invalid or uncatchable.
        Raise RuntimeError if there is a problem setting up the handler.
        z3coroutines cannot be used with add_signal_handler()NF���zset_wakeup_fd(-1) failed: %szsig z cannot be caught)rZiscoroutineZiscoroutinefunction�	TypeError�
_check_signalZ
_check_closed�signal�
set_wakeup_fdZ_csock�fileno�
ValueError�OSError�RuntimeError�strrZHandlerr�siginterruptr�info�errno�EINVAL)rr(�callback�args�exc�handleZnexcrrr�add_signal_handlerKs0



z)_UnixSelectorEventLoop.add_signal_handlercCs8|j�|�}|dkrdS|jr*|�|�n
|�|�dS)z2Internal helper that is the actual signal handler.N)r�getZ
_cancelledr#Z_add_callback_signalsafe)rr(r=rrrr)xsz%_UnixSelectorEventLoop._handle_signalc
Cs�|�|�y|j|=Wntk
r*dSX|tjkr>tj}ntj}yt�||�WnBtk
r�}z$|jtj	kr�t
d|�d���n�Wdd}~XYnX|js�yt�d�Wn2ttfk
r�}zt
�d|�Wdd}~XYnXdS)zwRemove a handler for a signal.  UNIX only.

        Return True if a signal handler was removed, False if not.
        Fzsig z cannot be caughtNr,zset_wakeup_fd(-1) failed: %sT)r.r�KeyErrorr/�SIGINT�default_int_handler�SIG_DFLr3r8r9r4r0r2rr7)rr(Zhandlerr<rrrr#�s(

z,_UnixSelectorEventLoop.remove_signal_handlercCsLt|t�std|����d|kr.tjksHntd|�dtj�d���dS)z�Internal helper to validate a signal.

        Raise ValueError if the signal number is invalid or uncatchable.
        Raise RuntimeError if there is a problem setting up the handler.
        zsig must be an int, not rzsig z out of range(1, �)N)�
isinstance�intr-r/�NSIGr2)rr(rrrr.�s
z$_UnixSelectorEventLoop._check_signalcCst|||||�S)N)�_UnixReadPipeTransport)r�pipe�protocol�waiter�extrarrr�_make_read_pipe_transport�sz0_UnixSelectorEventLoop._make_read_pipe_transportcCst|||||�S)N)�_UnixWritePipeTransport)rrIrJrKrLrrr�_make_write_pipe_transport�sz1_UnixSelectorEventLoop._make_write_pipe_transportc	

�s�t����}
|��}t||||||||f||d�|	��}|
�|��|j|�y|IdHWn,tk
r�|��|�	�IdH�YnXWdQRX|S)N)rKrL)
r�get_child_watcher�
create_future�_UnixSubprocessTransport�add_child_handlerZget_pid�_child_watcher_callback�	ExceptionrZ_wait)
rrJr;�shell�stdin�stdout�stderr�bufsizerL�kwargs�watcherrK�transprrr�_make_subprocess_transport�s




z1_UnixSelectorEventLoop._make_subprocess_transportcCs|�|j|�dS)N)Zcall_soon_threadsafeZ_process_exited)r�pid�
returncoder]rrrrT�sz._UnixSelectorEventLoop._child_watcher_callback)�ssl�sock�server_hostname�ssl_handshake_timeoutc	�s |dkst|t�st�|r,|dkrLtd��n |dk	r<td��|dk	rLtd��|dk	r�|dk	rdtd��t�|�}t�tjtjd�}y |�	d�|�
||�IdHWq�|���Yq�Xn@|dkr�td��|jtjks�|j
tjkr�td|����|�	d�|j|||||d	�IdH\}}||fS)
Nz/you have to pass server_hostname when using sslz+server_hostname is only meaningful with sslz1ssl_handshake_timeout is only meaningful with sslz3path and sock can not be specified at the same timerFzno path and sock were specifiedz.A UNIX Domain Stream Socket was expected, got )rd)rEr5�AssertionErrorr2�os�fspath�socket�AF_UNIX�SOCK_STREAM�setblockingZsock_connectr�family�typeZ_create_connection_transport)	r�protocol_factory�pathrarbrcrd�	transportrJrrr�create_unix_connection�sB



z-_UnixSelectorEventLoop.create_unix_connection�dT)rb�backlogrard�
start_servingc
�s�t|t�rtd��|dk	r&|s&td��|dk	�rH|dk	r@td��t�|�}t�tjtj�}|ddkr�y t	�
t�	|�j�r�t�|�WnBt
k
r�Yn0tk
r�}zt�d||�Wdd}~XYnXy|�|�Wnltk
�r0}	z8|��|	jtjk�rd|�d�}
ttj|
�d�n�Wdd}	~	XYn|���YnXn<|dk�rZtd	��|jtjk�sv|jtjk�r�td
|����|�d�t�||g||||�}|�r�|��tjd|d�IdH|S)
Nz*ssl argument must be an SSLContext or Nonez1ssl_handshake_timeout is only meaningful with sslz3path and sock can not be specified at the same timer)r�z2Unable to check or remove stale UNIX socket %r: %rzAddress z is already in usez-path was not specified, and no sock specifiedz.A UNIX Domain Stream Socket was expected, got F)�loop)rE�boolr-r2rfrgrhrirj�stat�S_ISSOCK�st_mode�remove�FileNotFoundErrorr3r�errorZbindrr8Z
EADDRINUSErlrmrkrZServerZ_start_servingr
Zsleep)rrnrorbrsrardrt�errr<�msgZserverrrr�create_unix_server�sZ






z)_UnixSelectorEventLoop.create_unix_serverc
�s�y
tjWn,tk
r6}zt�d��Wdd}~XYnXy|��}Wn2ttjfk
rv}zt�d��Wdd}~XYnXyt�|�j	}Wn,t
k
r�}zt�d��Wdd}~XYnX|r�|n|}	|	s�dS|��}
|�|
d|||||	d�|
IdHS)Nzos.sendfile() is not availableznot a regular filer)
rf�sendfile�AttributeErrorr�SendfileNotAvailableErrorr1�io�UnsupportedOperation�fstat�st_sizer3rQ�_sock_sendfile_native_impl)rrb�file�offset�countr<r1r~Zfsize�	blocksize�futrrr�_sock_sendfile_native>s(
z,_UnixSelectorEventLoop._sock_sendfile_nativec	Cs|��}	|dk	r|�|�|��r4|�|||�dS|rd||}|dkrd|�|||�|�|�dSyt�|	|||�}
W�n*ttfk
r�|dkr�|�	||�|�
|	|j||	||||||�
Y�nHtk
�rj}z�|dk	�r|j
t
jk�rt|�tk	�rtdt
j�}||_|}|dk�rBt�d�}
|�|||�|�|
�n|�|||�|�|�Wdd}~XYn�tk
�r�}z|�|||�|�|�Wdd}~XYnjX|
dk�r�|�|||�|�|�nD||
7}||
7}|dk�r�|�	||�|�
|	|j||	||||||�
dS)Nrzsocket is not connectedzos.sendfile call failed)r1�
remove_writer�	cancelled�_sock_sendfile_update_fileposZ
set_resultrfr��BlockingIOError�InterruptedError�_sock_add_cancellation_callbackZ
add_writerr�r3r8ZENOTCONNrm�ConnectionError�	__cause__rr�Z
set_exceptionrU)rr�Z
registered_fdrbr1r�r�r��
total_sent�fdZsentr<�new_excr~rrrr�Us`






z1_UnixSelectorEventLoop._sock_sendfile_native_implcCs|dkrt�||tj�dS)Nr)rf�lseek�SEEK_SET)rr1r�r�rrrr��sz4_UnixSelectorEventLoop._sock_sendfile_update_fileposcs��fdd�}|�|�dS)Ncs&|��r"���}|dkr"��|�dS)Nr,)r�r1r�)r�r�)rrbrr�cb�szB_UnixSelectorEventLoop._sock_add_cancellation_callback.<locals>.cb)Zadd_done_callback)rr�rbr�r)rrbrr��sz6_UnixSelectorEventLoop._sock_add_cancellation_callback)N)NN)NN)N)N)N)�__name__�
__module__�__qualname__�__doc__rrr+r>r)r#r.rMrOr^rTrqr�r�r�r�r��
__classcell__rr)rrr,s4-
 


*?Drcs�eZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
ddd�Zdd�Zdd�Z�ZS) rHiNcs�t��|�||jd<||_||_|��|_||_d|_d|_	t
�|j�j}t
�|�s�t
�|�s�t
�|�s�d|_d|_d|_td��t
�|jd�|j�|jj|�|j�|jj|j|j�|dk	r�|j�tj|d�dS)NrIFz)Pipe transport is for pipes/sockets only.)rr�_extra�_loop�_piper1�_fileno�	_protocol�_closing�_pausedrfr�rzrx�S_ISFIFOry�S_ISCHRr2�set_blocking�	call_soon�connection_made�_add_reader�_read_readyr�_set_result_unless_cancelled)rrvrIrJrKrL�mode)rrrr�s.





z_UnixReadPipeTransport.__init__cCs�|jjg}|jdkr |�d�n|jr0|�d�|�d|j���t|jdd�}|jdk	r�|dk	r�t�	||jt
j�}|r�|�d�q�|�d�n |jdk	r�|�d�n
|�d�d�d	�
|��S)
N�closed�closingzfd=�	_selector�polling�idle�openz<{}>� )rr�r��appendr�r��getattrr�r	�_test_selector_event�	selectorsZ
EVENT_READ�format�join)rr7rr�rrr�__repr__�s"




z_UnixReadPipeTransport.__repr__c
Cs�yt�|j|j�}WnDttfk
r,Yn�tk
rX}z|�|d�Wdd}~XYn^X|rl|j�	|�nJ|j
��r�t�
d|�d|_|j
�|j�|j
�|jj�|j
�|jd�dS)Nz"Fatal read error on pipe transportz%r was closed by peerT)rf�readr��max_sizer�r�r3�_fatal_errorr�Z
data_receivedr��	get_debugrr7r��_remove_readerr�Zeof_received�_call_connection_lost)rr*r<rrrr��s
z"_UnixReadPipeTransport._read_readycCs>|js|jrdSd|_|j�|j�|j��r:t�d|�dS)NTz%r pauses reading)r�r�r�r�r�r�r�debug)rrrr�
pause_reading�s
z$_UnixReadPipeTransport.pause_readingcCsB|js|jsdSd|_|j�|j|j�|j��r>t�d|�dS)NFz%r resumes reading)	r�r�r�r�r�r�r�rr�)rrrr�resume_reading�s
z%_UnixReadPipeTransport.resume_readingcCs
||_dS)N)r�)rrJrrr�set_protocol�sz#_UnixReadPipeTransport.set_protocolcCs|jS)N)r�)rrrr�get_protocolsz#_UnixReadPipeTransport.get_protocolcCs|jS)N)r�)rrrr�
is_closingsz!_UnixReadPipeTransport.is_closingcCs|js|�d�dS)N)r��_close)rrrrrsz_UnixReadPipeTransport.closecCs.|jdk	r*tjd|��t|d�|j��dS)Nzunclosed transport )r)r�r$r%r&r)rrrr�__del__s
z_UnixReadPipeTransport.__del__�Fatal error on pipe transportcCsZt|t�r4|jtjkr4|j��rLtjd||dd�n|j�||||j	d��|�
|�dS)Nz%r: %sT)�exc_info)�message�	exceptionrprJ)rEr3r8ZEIOr�r�rr��call_exception_handlerr�r�)rr<r�rrrr�s
z#_UnixReadPipeTransport._fatal_errorcCs(d|_|j�|j�|j�|j|�dS)NT)r�r�r�r�r�r�)rr<rrrr� sz_UnixReadPipeTransport._closecCs4z|j�|�Wd|j��d|_d|_d|_XdS)N)r��connection_lostr�rr�)rr<rrrr�%s
z,_UnixReadPipeTransport._call_connection_lost)NN)r�)r�r�r�r�rr�r�r�r�r�r�r�rr�r�r�r�r�rr)rrrH�s
rHcs�eZdZd%�fdd�	Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd&dd �Zd'd!d"�Zd#d$�Z�ZS)(rNNc
s�t��||�||jd<||_|��|_||_t�|_d|_	d|_
t�|j�j
}t�|�}t�|�}t�|�}	|s�|s�|	s�d|_d|_d|_td��t�|jd�|j�|jj|�|	s�|r�tj�d�s�|j�|jj|j|j�|dk	r�|j�tj|d�dS)NrIrFz?Pipe transport is only for pipes, sockets and character devicesZaix)rrr�r�r1r�r��	bytearray�_buffer�
_conn_lostr�rfr�rzrxr�r�ryr2r�r�r�r�r �platform�
startswithr�r�rr�)
rrvrIrJrKrLr�Zis_charZis_fifoZ	is_socket)rrrr2s2





z _UnixWritePipeTransport.__init__cCs�|jjg}|jdkr |�d�n|jr0|�d�|�d|j���t|jdd�}|jdk	r�|dk	r�t�	||jt
j�}|r�|�d�n
|�d�|��}|�d|���n |jdk	r�|�d�n
|�d�d	�
d
�|��S)Nr�r�zfd=r�r�r�zbufsize=r�z<{}>r�)rr�r�r�r�r�r�r�r	r�r�ZEVENT_WRITE�get_write_buffer_sizer�r�)rr7rr�rZrrrr�Ws&





z _UnixWritePipeTransport.__repr__cCs
t|j�S)N)�lenr�)rrrrr�osz-_UnixWritePipeTransport.get_write_buffer_sizecCs6|j��rt�d|�|jr*|�t��n|��dS)Nz%r was closed by peer)r�r�rr7r�r��BrokenPipeError)rrrrr�rs

z#_UnixWritePipeTransport._read_readyc
Cs2t|tttf�stt|���t|t�r.t|�}|s6dS|jsB|jrj|jtj	krXt
�d�|jd7_dS|j�syt
�|j|�}WnVttfk
r�d}Yn<tk
r�}z|jd7_|�|d�dSd}~XYnX|t|�kr�dS|dk�rt|�|d�}|j�|j|j�|j|7_|��dS)Nz=pipe closed by peer or os.write(pipe, data) raised exception.rrz#Fatal write error on pipe transport)rE�bytesr��
memoryviewre�reprr�r�rZ!LOG_THRESHOLD_FOR_CONNLOST_WRITESr�warningr�rf�writer�r�r�rUr�r�r�Z_add_writer�_write_readyZ_maybe_pause_protocol)rr*�nr<rrrr�{s4


z_UnixWritePipeTransport.writec
Cs�|jstd��yt�|j|j�}Wnjttfk
r:Yn�tk
r�}z6|j��|j	d7_	|j
�|j�|�|d�Wdd}~XYnfX|t
|j�kr�|j��|j
�|j�|��|jr�|j
�|j�|�d�dS|dkr�|jd|�=dS)NzData should not be emptyrz#Fatal write error on pipe transportr)r�rerfr�r�r�r�rUr'r�r��_remove_writerr�r�Z_maybe_resume_protocolr�r�r�)rr�r<rrrr��s(


z$_UnixWritePipeTransport._write_readycCsdS)NTr)rrrr�
can_write_eof�sz%_UnixWritePipeTransport.can_write_eofcCsB|jr
dS|jst�d|_|js>|j�|j�|j�|jd�dS)NT)	r�r�rer�r�r�r�r�r�)rrrr�	write_eof�s
z!_UnixWritePipeTransport.write_eofcCs
||_dS)N)r�)rrJrrrr��sz$_UnixWritePipeTransport.set_protocolcCs|jS)N)r�)rrrrr��sz$_UnixWritePipeTransport.get_protocolcCs|jS)N)r�)rrrrr��sz"_UnixWritePipeTransport.is_closingcCs|jdk	r|js|��dS)N)r�r�r�)rrrrr�sz_UnixWritePipeTransport.closecCs.|jdk	r*tjd|��t|d�|j��dS)Nzunclosed transport )r)r�r$r%r&r)rrrrr��s
z_UnixWritePipeTransport.__del__cCs|�d�dS)N)r�)rrrr�abort�sz_UnixWritePipeTransport.abort�Fatal error on pipe transportcCsNt|t�r(|j��r@tjd||dd�n|j�||||jd��|�|�dS)Nz%r: %sT)r�)r�r�rprJ)	rEr3r�r�rr�r�r�r�)rr<r�rrrr��s

z$_UnixWritePipeTransport._fatal_errorcCsFd|_|jr|j�|j�|j��|j�|j�|j�|j|�dS)NT)	r�r�r�r�r�r'r�r�r�)rr<rrrr��s
z_UnixWritePipeTransport._closecCs4z|j�|�Wd|j��d|_d|_d|_XdS)N)r�r�r�rr�)rr<rrrr��s
z-_UnixWritePipeTransport._call_connection_lost)NN)r�)N)r�r�r�rr�r�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�rr)rrrN/s"%	!	

rNc@seZdZdd�ZdS)rRc		Ks�d}|tjkrt��\}}zPtj|f||||d|d�|��|_|dk	rh|��t|��d|d�|j_	d}Wd|dk	r�|��|��XdS)NF)rVrWrXrYZuniversal_newlinesrZ�wb)�	buffering)
�
subprocess�PIPErhZ
socketpair�Popen�_procrr��detachrW)	rr;rVrWrXrYrZr[Zstdin_wrrr�_start�s
z_UnixSubprocessTransport._startN)r�r�r�r�rrrrrR�srRc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)raHAbstract base class for monitoring child processes.

    Objects derived from this class monitor a collection of subprocesses and
    report their termination or interruption by a signal.

    New callbacks are registered with .add_child_handler(). Starting a new
    process must be done within a 'with' block to allow the watcher to suspend
    its activity until the new process if fully registered (this is needed to
    prevent a race condition in some implementations).

    Example:
        with watcher:
            proc = subprocess.Popen("sleep 1")
            watcher.add_child_handler(proc.pid, callback)

    Notes:
        Implementations of this class must be thread-safe.

        Since child watcher objects may catch the SIGCHLD signal and call
        waitpid(-1), there should be only one active object per process.
    cGs
t��dS)aRegister a new child handler.

        Arrange for callback(pid, returncode, *args) to be called when
        process 'pid' terminates. Specifying another callback for the same
        process replaces the previous handler.

        Note: callback() must be thread-safe.
        N)�NotImplementedError)rr_r:r;rrrrS)s	z&AbstractChildWatcher.add_child_handlercCs
t��dS)z�Removes the handler for process 'pid'.

        The function returns True if the handler was successfully removed,
        False if there was nothing to remove.N)r�)rr_rrr�remove_child_handler4sz)AbstractChildWatcher.remove_child_handlercCs
t��dS)z�Attach the watcher to an event loop.

        If the watcher was previously attached to an event loop, then it is
        first detached before attaching to the new loop.

        Note: loop may be None.
        N)r�)rrvrrr�attach_loop<sz AbstractChildWatcher.attach_loopcCs
t��dS)zlClose the watcher.

        This must be called to make sure that any underlying resource is freed.
        N)r�)rrrrrFszAbstractChildWatcher.closecCs
t��dS)zdEnter the watcher's context and allow starting new processes

        This function must return selfN)r�)rrrr�	__enter__MszAbstractChildWatcher.__enter__cCs
t��dS)zExit the watcher's contextN)r�)r�a�b�crrr�__exit__SszAbstractChildWatcher.__exit__N)
r�r�r�r�rSr�r�rr�r�rrrrrs
rc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�BaseChildWatchercCsd|_i|_dS)N)r��
_callbacks)rrrrrZszBaseChildWatcher.__init__cCs|�d�dS)N)r�)rrrrr^szBaseChildWatcher.closecCs
t��dS)N)r�)r�expected_pidrrr�_do_waitpidaszBaseChildWatcher._do_waitpidcCs
t��dS)N)r�)rrrr�_do_waitpid_alldsz BaseChildWatcher._do_waitpid_allcCs~|dkst|tj�st�|jdk	r<|dkr<|jr<t�dt�|jdk	rT|j�	t
j�||_|dk	rz|�t
j|j
�|��dS)NzCA loop is being detached from a child watcher with pending handlers)rErZAbstractEventLooprer�r�r$r%�RuntimeWarningr#r/�SIGCHLDr>�	_sig_chldr�)rrvrrrr�gs
zBaseChildWatcher.attach_loopc
CsFy|��Wn4tk
r@}z|j�d|d��Wdd}~XYnXdS)Nz$Unknown exception in SIGCHLD handler)r�r�)r�rUr�r�)rr<rrrr�{szBaseChildWatcher._sig_chldcCs2t�|�rt�|�St�|�r*t�|�S|SdS)N)rf�WIFSIGNALED�WTERMSIG�	WIFEXITED�WEXITSTATUS)r�statusrrr�_compute_returncode�s



z$BaseChildWatcher._compute_returncodeN)
r�r�r�rrr�r�r�r�rrrrrr�Xsr�csPeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
�ZS)rad'Safe' child watcher implementation.

    This implementation avoids disrupting other code spawning processes by
    polling explicitly each process in the SIGCHLD handler instead of calling
    os.waitpid(-1).

    This is a safe solution but it has a significant overhead when handling a
    big number of children (O(n) each time SIGCHLD is raised)
    cs|j��t���dS)N)r�r'rr)r)rrrr�s
zSafeChildWatcher.closecCs|S)Nr)rrrrr��szSafeChildWatcher.__enter__cCsdS)Nr)rr�r�r�rrrr��szSafeChildWatcher.__exit__cGs.|jdkrtd��||f|j|<|�|�dS)NzICannot add child handler, the child watcher does not have a loop attached)r�r4r�r�)rr_r:r;rrrrS�s

z"SafeChildWatcher.add_child_handlercCs&y|j|=dStk
r dSXdS)NTF)r�r@)rr_rrrr��s
z%SafeChildWatcher.remove_child_handlercCs"xt|j�D]}|�|�qWdS)N)r"r�r�)rr_rrrr��sz SafeChildWatcher._do_waitpid_allcCs�|dkst�yt�|tj�\}}Wn(tk
rJ|}d}t�d|�Yn0X|dkrXdS|�|�}|j�	�rzt�
d||�y|j�|�\}}Wn.t
k
r�|j�	�r�tjd|dd�YnX|||f|��dS)Nr�z8Unknown child process pid %d, will report returncode 255z$process %s exited with returncode %sz'Child watcher got an unexpected pid: %rT)r�)rerf�waitpid�WNOHANG�ChildProcessErrorrr�rr�r�r�r��popr@)rr�r_rr`r:r;rrrr��s,


zSafeChildWatcher._do_waitpid)r�r�r�r�rr�r�rSr�r�r�r�rr)rrr�s	rcsTeZdZdZ�fdd�Z�fdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
�ZS)raW'Fast' child watcher implementation.

    This implementation reaps every terminated processes by calling
    os.waitpid(-1) directly, possibly breaking other code spawning processes
    and waiting for their termination.

    There is no noticeable overhead when handling a big number of children
    (O(1) each time a child terminates).
    cs$t���t��|_i|_d|_dS)Nr)rr�	threadingZLock�_lock�_zombies�_forks)r)rrrr�s

zFastChildWatcher.__init__cs"|j��|j��t���dS)N)r�r'r
rr)r)rrrr�s

zFastChildWatcher.closec	Cs$|j�|jd7_|SQRXdS)Nr)rr)rrrrr��szFastChildWatcher.__enter__c	CsT|j�8|jd8_|js"|js&dSt|j�}|j��WdQRXt�d|�dS)Nrz5Caught subprocesses termination from unknown pids: %s)rrr
r5r'rr�)rr�r�r�Zcollateral_victimsrrrr��s
zFastChildWatcher.__exit__c	Gsz|jstd��|jdkr td��|j�:y|j�|�}Wn"tk
rZ||f|j|<dSXWdQRX|||f|��dS)NzMust use the context managerzICannot add child handler, the child watcher does not have a loop attached)	rrer�r4rr
r
r@r�)rr_r:r;r`rrrrS
s
z"FastChildWatcher.add_child_handlercCs&y|j|=dStk
r dSXdS)NTF)r�r@)rr_rrrr� s
z%FastChildWatcher.remove_child_handlerc	Cs�x�yt�dtj�\}}Wntk
r,dSX|dkr:dS|�|�}|j�vy|j�|�\}}WnBtk
r�|j	r�||j
|<|j��r�t
�d||�wd}YnX|j��r�t
�d||�WdQRX|dkr�t
�d||�q|||f|��qWdS)Nr,rz,unknown process %s exited with returncode %sz$process %s exited with returncode %sz8Caught subprocess termination from unknown pid: %d -> %d)rfrrr	rrr�r
r@rr
r�r�rr�r�)rr_rr`r:r;rrrr�'s6





z FastChildWatcher._do_waitpid_all)r�r�r�r�rrr�r�rSr�r�r�rr)rrr�s	rcsHeZdZdZeZ�fdd�Zdd�Z�fdd�Zdd	�Z	d
d�Z
�ZS)�_UnixDefaultEventLoopPolicyz:UNIX event loop policy with a watcher for child processes.cst���d|_dS)N)rr�_watcher)r)rrrrVs
z$_UnixDefaultEventLoopPolicy.__init__c	CsHtj�8|jdkr:t�|_tt��tj�r:|j�|j	j
�WdQRXdS)N)rrrrrEr�current_thread�_MainThreadr��_localr�)rrrr�
_init_watcherZs
z)_UnixDefaultEventLoopPolicy._init_watchercs6t��|�|jdk	r2tt��tj�r2|j�|�dS)z�Set the event loop.

        As a side effect, if a child watcher was set before, then calling
        .set_event_loop() from the main thread will call .attach_loop(loop) on
        the child watcher.
        N)r�set_event_looprrErrrr�)rrv)rrrrbs
z*_UnixDefaultEventLoopPolicy.set_event_loopcCs|jdkr|��|jS)zzGet the watcher for child processes.

        If not yet set, a SafeChildWatcher object is automatically created.
        N)rr)rrrrrPps
z-_UnixDefaultEventLoopPolicy.get_child_watchercCs4|dkst|t�st�|jdk	r*|j��||_dS)z$Set the watcher for child processes.N)rErrerr)rr\rrr�set_child_watcherzs

z-_UnixDefaultEventLoopPolicy.set_child_watcher)r�r�r�r�rZ
_loop_factoryrrrrPrr�rr)rrrRs
r)-r�r8r�rfr�r/rhrxr�r rr$�rrrrrrr	r
r�logr�__all__r��ImportErrorrZBaseSelectorEventLooprZ
ReadTransportrHZ_FlowControlMixinZWriteTransportrNZBaseSubprocessTransportrRrr�rrZBaseDefaultEventLoopPolicyrr
rrrrr�<module>sR
|
JF=On3

Hacked By AnonymousFox1.0, Coded By AnonymousFox