OwlCyberSecurity - MANAGER
Edit File: unix_events.cpython-36.opt-1.pyc
3 � f����������������� ���@���s ��d�Z�ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl mZ�ddl mZ�ddl m Z �ddl mZ�ddl mZ�dd l mZ�dd l mZ�ddl mZ�ddl mZ�dd l mZ�ddlmZ�ddlmZ�dddddgZejdkr�ed��dd��Zy ejZW�n�ek �r,���dd��ZY�nX�G�dd��dej�Z e!ed��rVdd��Z"nddl#Z#d d��Z"G�d!d"��d"ej$�Z%G�d#d$��d$ej&ej'�Z(e!ed%��r�ej)Z*nddl#Z#d&d'��Z*G�d(d)��d)ej+�Z,G�d*d��d�Z-G�d+d,��d,e-�Z.G�d-d��de.�Z/G�d.d��de.�Z0G�d/d0��d0ej1�Z2e Z3e2Z4dS�)1z2Selector event loop for Unix with signal handling.�����N����)�base_events)�base_subprocess)�compat)� constants)� coroutines)�events)�futures)�selector_events)� selectors)� transports)� coroutine)�logger�SelectorEventLoop�AbstractChildWatcher�SafeChildWatcher�FastChildWatcher�DefaultEventLoopPolicyZwin32z+Signals are not really supported on Windowsc�������������C���s���dS�)zDummy signal handler.N��)�signum�framer���r����8/opt/alt/python36/lib64/python3.6/asyncio/unix_events.py�_sighandler_noop%���s����r���c�������������C���s���|�S�)Nr���)�pathr���r���r����<lambda>.���s����r���c�������������������s����e�Zd�ZdZd"��fdd� Zdd��Z��fdd�Zd d ��Zdd��Zd d��Z dd��Z dd��Zd#dd�Zd$dd�Z ed%dd��Zdd��Zedddd�dd��Zed&dddd�d d!��Z���ZS�)'�_UnixSelectorEventLoopzdUnix event loop. Adds signal handling and UNIX Domain Socket support to SelectorEventLoop. Nc����������������s���t���j|��i�|�_d�S�)N)�super�__init__�_signal_handlers)�self�selector)� __class__r���r���r���7���s����z_UnixSelectorEventLoop.__init__c�������������C���s���t�j��S�)N)�socketZ socketpair)r���r���r���r����_socketpair;���s����z"_UnixSelectorEventLoop._socketpairc����������������s^���t���j���tj��s2xFt|�j�D�]}|�j|��qW�n(|�jrZtjd|��d�t |�d��|�jj ���d�S�)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)r!���r���r���r%���>���s���� z_UnixSelectorEventLoop.closec�������������C���s"���x|D�]}|sq|�j�|��qW�d�S�)N)�_handle_signal)r����datar���r���r���r����_process_self_dataL���s���� z)_UnixSelectorEventLoop._process_self_datac����������+���G���sH��t�j|�st�j|�rtd��|�j|��|�j���ytj|�jj ����W�n2�t tfk rt�}�ztt |���W�Y�dd}~X�nX�tj|||��}||�j|<�ytj|t��tj|d��W�n��tk �rB�}�zz|�j|=�|�j�sytjd��W�n4�t tfk �r�}�ztjd|��W�Y�dd}~X�nX�|jtjk�r0tdj|���n��W�Y�dd}~X�nX�dS�)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()NFr���zset_wakeup_fd(-1) failed: %szsig {} cannot be caught���)r���ZiscoroutineZiscoroutinefunction� TypeError� _check_signalZ _check_closed�signal� set_wakeup_fdZ_csock�fileno� ValueError�OSError�RuntimeError�strr���ZHandler���r����siginterruptr����info�errno�EINVAL�format)r���r.����callback�args�exc�handleZnexcr���r���r����add_signal_handlerS���s0���� z)_UnixSelectorEventLoop.add_signal_handlerc�������������C���s8���|�j�j|�}|dkrdS�|jr*|�j|��n |�j|��dS�)z2Internal helper that is the actual signal handler.N)r����getZ _cancelledr)���Z_add_callback_signalsafe)r���r.���rD���r���r���r���r/�������s����z%_UnixSelectorEventLoop._handle_signalc����������&���C���s����|�j�|��y|�j|=�W�n�tk r*���dS�X�|tjkr>tj}ntj}ytj||��W�n@�tk r��}�z$|jtj kr�t dj|���n��W�Y�dd}~X�nX�|�js�ytjd��W�n2�t tfk r��}�ztjd|��W�Y�dd}~X�nX�dS�)zwRemove a handler for a signal. UNIX only. Return True if a signal handler was removed, False if not. Fzsig {} cannot be caughtNr���zset_wakeup_fd(-1) failed: %sTr2���)r4���r����KeyErrorr5����SIGINT�default_int_handler�SIG_DFLr9���r>���r?���r:���r@���r6���r8���r���r=���)r���r.���ZhandlerrC���r���r���r���r)�������s(���� z,_UnixSelectorEventLoop.remove_signal_handlerc�������������C���sH���t�|t�stdj|���d|��ko,tjk�n��sDtdj|tj���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 {!r}r���zsig {} out of range(1, {})N)� isinstance�intr3���r@���r5����NSIGr8���)r���r.���r���r���r���r4�������s ���� z$_UnixSelectorEventLoop._check_signalc�������������C���s���t�|�||||�S�)N)�_UnixReadPipeTransport)r����pipe�protocol�waiter�extrar���r���r����_make_read_pipe_transport����s����z0_UnixSelectorEventLoop._make_read_pipe_transportc�������������C���s���t�|�||||�S�)N)�_UnixWritePipeTransport)r���rO���rP���rQ���rR���r���r���r����_make_write_pipe_transport����s����z1_UnixSelectorEventLoop._make_write_pipe_transportc �������������k���s����t�j����} |�j��}t|�|||||||f||d�| ��}| j|j��|�j|��y|E�d�H��W�n&�tk r~�} �z | }W�Y�d�d�} ~ X�nX�d�}|d�k r�|j���|j ��E�d�H��|�W�d�Q�R�X�|S�)N)rQ���rR���) r����get_child_watcherZ create_future�_UnixSubprocessTransport�add_child_handlerZget_pid�_child_watcher_callback� Exceptionr%���Z_wait)r���rP���rB����shell�stdin�stdout�stderr�bufsizerR����kwargs�watcherrQ����transprC����errr���r���r����_make_subprocess_transport����s$���� z1_UnixSelectorEventLoop._make_subprocess_transportc�������������C���s���|�j�|j|��d�S�)N)Zcall_soon_threadsafeZ_process_exited)r����pid� returncoderb���r���r���r���rY�������s����z._UnixSelectorEventLoop._child_watcher_callback)�ssl�sock�server_hostnamec������������c���s����|r|d�kr&t�d��n|d�k r&t�d��|d�k r�|d�k r>t�d��tjtjtjd�}y |jd��|�j||�E�d�H��W�q����|j�����Y�q�X�nB|d�kr�t�d��|jtjks�tj |j ��r�t�dj|���|jd��|�j||||�E�d�H�\}}||fS�)Nz/you have to pass server_hostname when using sslz+server_hostname is only meaningful with sslz3path and sock can not be specified at the same timer���Fzno path and sock were specifiedz2A UNIX Domain Stream Socket was expected, got {!r}) r8���r"����AF_UNIX�SOCK_STREAM�setblockingZsock_connectr%����familyr����_is_stream_socket�typer@���Z_create_connection_transport)r����protocol_factoryr���rg���rh���ri���� transportrP���r���r���r����create_unix_connection����s8���� z-_UnixSelectorEventLoop.create_unix_connection�d���)rh����backlogrg���c������ ���!���C���s���t�|t�rtd��|d�k �r0|d�k r,td��t|�}tjtjtj�}|d�d kr�y tj t j|�j�rnt j|��W�nB�t k r����Y�n0�tk r��}�ztjd||��W�Y�d�d�}~X�nX�y|j|��W�nj�tk �r�}�z8|j���|jtjk�rdj|�}ttj|�d��n��W�Y�d�d�}~X�n���|j�����Y�nX�n>|d�k�rBtd��|jtjk�s`tj|j���rntdj|���tj|�|g�} |j|��|jd ��|�j|||| ��| S�)Nz*ssl argument must be an SSLContext or Nonez3path and sock can not be specified at the same timer�����z2Unable to check or remove stale UNIX socket %r: %rzAddress {!r} is already in usez-path was not specified, and no sock specifiedz2A UNIX Domain Stream Socket was expected, got {!r}F)r���ru���)rK����boolr3���r8����_fspathr"���rj���rk����stat�S_ISSOCK�os�st_mode�remove�FileNotFoundErrorr9���r����errorZbindr%���r>���Z EADDRINUSEr@���rm���r���rn���ro���ZServerZlistenrl���Z_start_serving) r���rp���r���rh���rt���rg���rc���rC����msgZserverr���r���r����create_unix_server��sP���� z)_UnixSelectorEventLoop.create_unix_server)N)NN)NN)N)N)�__name__� __module__�__qualname__�__doc__r���r#���r%���r1���rE���r/���r)���r4���rS���rU���r ���rd���rY���rr���r����� __classcell__r���r���)r!���r���r���1���s,���- � � %r����set_blockingc�������������C���s���t�j|�d��d�S�)NF)rz���r����)�fdr���r���r����_set_nonblockingB��s����r����c�������������C���s,���t�j�|�t�j�}|tjB�}t�j�|�t�j|��d�S�)N)�fcntlZF_GETFLrz���� O_NONBLOCKZF_SETFL)r�����flagsr���r���r���r����G��s���� c�������������������s����e�Zd�ZdZd ��fdd� Zdd��Zdd ��Zd d��Zdd ��Zdd��Z dd��Z dd��Zdd��Ze jrhdd��Zd!dd�Zdd��Zdd��Z���ZS�)"rN�������i���Nc����������������s����t���j|��||�jd<�||�_||�_|j��|�_||�_d|�_t j |�j�j}tj |�pbtj|�pbtj|�s~d�|�_d�|�_d�|�_td��t|�j��|�jj|�jj|���|�jj|�jj|�j|�j��|d�k r�|�jjtj|d���d�S�)NrO���Fz)Pipe transport is for pipes/sockets only.)r���r����_extra�_loop�_piper7����_fileno� _protocol�_closingrz����fstatr{���rx����S_ISFIFOry����S_ISCHRr8���r����� call_soon�connection_made�_add_reader�_read_readyr ����_set_result_unless_cancelled)r����looprO���rP���rQ���rR����mode)r!���r���r���r���Q��s,���� z_UnixReadPipeTransport.__init__c�������������C���s����|�j�jg}|�jd�kr |jd��n|�jr0|jd��|jd|�j���t|�jdd��}|�jd�k r�|d�k r�tj ||�jt j�}|r�|jd��q�|jd��n |�jd�k r�|jd��n |jd��dd j|��S�) N�closed�closingzfd=%s� _selector�polling�idle�openz<%s>� ) r!���r����r�����appendr����r�����getattrr����r ����_test_selector_eventr���Z EVENT_READ�join)r���r=���r ���r����r���r���r����__repr__n��s$���� z_UnixReadPipeTransport.__repr__c�������������C���s����yt�j|�j|�j�}W�nD�ttfk r,���Y�n��tk rX�}�z|�j|d��W�Y�d�d�}~X�n^X�|rl|�jj |��nJ|�j j��r�tj d|���d|�_|�j j|�j��|�j j|�jj��|�j j|�jd���d�S�)Nz"Fatal read error on pipe transportz%r was closed by peerT)rz����readr�����max_size�BlockingIOError�InterruptedErrorr9����_fatal_errorr����Z data_receivedr����� get_debugr���r=���r�����_remove_readerr����Zeof_received�_call_connection_lost)r���r0���rC���r���r���r���r�������s���� z"_UnixReadPipeTransport._read_readyc�������������C���s���|�j�j|�j��d�S�)N)r����r����r����)r���r���r���r���� pause_reading���s����z$_UnixReadPipeTransport.pause_readingc�������������C���s���|�j�j|�j|�j��d�S�)N)r����r����r����r����)r���r���r���r����resume_reading���s����z%_UnixReadPipeTransport.resume_readingc�������������C���s ���||�_�d�S�)N)r����)r���rP���r���r���r����set_protocol���s����z#_UnixReadPipeTransport.set_protocolc�������������C���s���|�j�S�)N)r����)r���r���r���r����get_protocol���s����z#_UnixReadPipeTransport.get_protocolc�������������C���s���|�j�S�)N)r����)r���r���r���r���� is_closing���s����z!_UnixReadPipeTransport.is_closingc�������������C���s���|�j�s|�jd���d�S�)N)r�����_close)r���r���r���r���r%������s����z_UnixReadPipeTransport.closec�������������C���s,���|�j�d�k r(tjd|��t|�d��|�j�j���d�S�)Nzunclosed transport %r)r$���)r����r*���r+���r,���r%���)r���r���r���r����__del__���s���� z_UnixReadPipeTransport.__del__�Fatal error on pipe transportc�������������C���sZ���t�|t�r4|jtjkr4|�jj��rLtjd|�|dd��n|�jj|||�|�j d���|�j |��d�S�)Nz%r: %sT)�exc_info)�message� exceptionrq���rP���)rK���r9���r>���ZEIOr����r����r����debug�call_exception_handlerr����r����)r���rC���r����r���r���r���r�������s���� z#_UnixReadPipeTransport._fatal_errorc�������������C���s(���d|�_�|�jj|�j��|�jj|�j|��d�S�)NT)r����r����r����r����r����r����)r���rC���r���r���r���r�������s����z_UnixReadPipeTransport._closec�������������C���s4���z|�j�j|��W�d�|�jj���d�|�_d�|�_�d�|�_X�d�S�)N)r�����connection_lostr����r%���r����)r���rC���r���r���r���r�������s���� z,_UnixReadPipeTransport._call_connection_losti���)NN)r����)r����r����r����r����r���r����r����r����r����r����r����r����r%���r����PY34r����r����r����r����r����r���r���)r!���r���rN���M��s��� rN���c�������������������s����e�Zd�Zd%��fdd� Zdd��Zdd��Zdd ��Zd d��Zdd ��Zdd��Z dd��Z dd��Zdd��Zdd��Z dd��Zejr|dd��Zdd��Zd&dd �Zd'd!d"�Zd#d$��Z���ZS�)(rT���Nc������� ���������s����t���j||��||�jd<�||�_|j��|�_||�_t��|�_d|�_ d|�_ tj|�j�j }tj|�}tj|�}tj|�} |px|px| s�d�|�_d�|�_d�|�_td��t|�j��|�jj|�jj|���| s�|r�tjjd��r�|�jj|�jj|�j|�j��|d�k r�|�jjtj|d���d�S�)NrO���r���Fz?Pipe transport is only for pipes, sockets and character devices�aix)r���r���r����r����r7���r����r����� bytearray�_buffer� _conn_lostr����rz���r����r{���rx���r����r����ry���r8���r����r����r����r����r&����platform� startswithr����r����r ���r����) r���r����rO���rP���rQ���rR���r����Zis_charZis_fifoZ is_socket)r!���r���r���r������s2���� z _UnixWritePipeTransport.__init__c�������������C���s����|�j�jg}|�jd�kr |jd��n|�jr0|jd��|jd|�j���t|�jdd��}|�jd�k r�|d�k r�tj ||�jt j�}|r�|jd��n |jd��|�j��}|jd|���n |�jd�k r�|jd��n |jd��d d j |��S�)Nr����r����zfd=%sr����r����r����z bufsize=%sr����z<%s>r����)r!���r����r����r����r����r����r����r����r ���r����r���ZEVENT_WRITE�get_write_buffer_sizer����)r���r=���r ���r����r_���r���r���r���r�������s(���� z _UnixWritePipeTransport.__repr__c�������������C���s ���t�|�j�S�)N)�lenr����)r���r���r���r���r������s����z-_UnixWritePipeTransport.get_write_buffer_sizec�������������C���s6���|�j�j��rtjd|���|�jr*|�jt����n|�j���d�S�)Nz%r was closed by peer)r����r����r���r=���r����r�����BrokenPipeError)r���r���r���r���r������s ���� z#_UnixWritePipeTransport._read_readyc�������������C���s��t�|t�rt|�}|sd�S�|�js&|�jrN|�jtjkr<tjd��|��jd7��_d�S�|�j ��s�yt j|�j|�}W�nT�t tfk r����d}Y�n:�tk r��}�z|��jd7��_|�j|d��d�S�d�}~X�nX�|t|�kr�d�S�|dkr�t|�|d���}|�jj|�j|�j��|��j |7��_ |�j���d�S�)Nz=pipe closed by peer or os.write(pipe, data) raised exception.r���r���z#Fatal write error on pipe transport)rK���r����� memoryviewr����r����r���Z!LOG_THRESHOLD_FOR_CONNLOST_WRITESr����warningr����rz����writer����r����r����rZ���r����r����r����Z_add_writer�_write_readyZ_maybe_pause_protocol)r���r0����nrC���r���r���r���r������s2���� z_UnixWritePipeTransport.writec�������������C���s����yt�j|�j|�j�}W�nj�ttfk r,���Y�n��tk r~�}�z8|�jj���|��jd7��_|�j j |�j��|�j|d��W�Y�d�d�}~X�nfX�|t|�j�kr�|�jj���|�j j |�j��|�j ���|�jr�|�j j|�j��|�jd���d�S�|dkr�|�jd�|�=�d�S�)Nr���z#Fatal write error on pipe transportr���)rz���r����r����r����r����r����rZ���r-���r����r�����_remove_writerr����r����Z_maybe_resume_protocolr����r����r����)r���r����rC���r���r���r���r����>��s&���� z$_UnixWritePipeTransport._write_readyc�������������C���s���dS�)NTr���)r���r���r���r���� can_write_eofX��s����z%_UnixWritePipeTransport.can_write_eofc�������������C���s8���|�j�r d�S�d|�_�|�js4|�jj|�j��|�jj|�jd���d�S�)NT)r����r����r����r����r����r����r����)r���r���r���r���� write_eof[��s����z!_UnixWritePipeTransport.write_eofc�������������C���s ���||�_�d�S�)N)r����)r���rP���r���r���r���r����d��s����z$_UnixWritePipeTransport.set_protocolc�������������C���s���|�j�S�)N)r����)r���r���r���r���r����g��s����z$_UnixWritePipeTransport.get_protocolc�������������C���s���|�j�S�)N)r����)r���r���r���r���r����j��s����z"_UnixWritePipeTransport.is_closingc�������������C���s���|�j�d�k r|�j�r|�j���d�S�)N)r����r����r����)r���r���r���r���r%���m��s����z_UnixWritePipeTransport.closec�������������C���s,���|�j�d�k r(tjd|��t|�d��|�j�j���d�S�)Nzunclosed transport %r)r$���)r����r*���r+���r,���r%���)r���r���r���r���r����v��s���� z_UnixWritePipeTransport.__del__c�������������C���s���|�j�d���d�S�)N)r����)r���r���r���r����abort|��s����z_UnixWritePipeTransport.abort�Fatal error on pipe transportc�������������C���sP���t�|tj�r*|�jj��rBtjd|�|dd��n|�jj|||�|�jd���|�j |��d�S�)Nz%r: %sT)r����)r����r����rq���rP���) rK���r���Z_FATAL_ERROR_IGNOREr����r����r���r����r����r����r����)r���rC���r����r���r���r���r������s���� z$_UnixWritePipeTransport._fatal_errorc�������������C���sF���d|�_�|�jr|�jj|�j��|�jj���|�jj|�j��|�jj|�j|��d�S�)NT) r����r����r����r����r����r-���r����r����r����)r���rC���r���r���r���r�������s���� z_UnixWritePipeTransport._closec�������������C���s4���z|�j�j|��W�d�|�jj���d�|�_d�|�_�d�|�_X�d�S�)N)r����r����r����r%���r����)r���rC���r���r���r���r�������s���� z-_UnixWritePipeTransport._call_connection_lost)NN)r����)N)r����r����r����r���r����r����r����r����r����r����r����r����r����r����r%���r���r����r����r����r����r����r����r����r���r���)r!���r���rT������s$���% ! rT����set_inheritablec�������������C���sN���t�tdd�}tj|�tj�}|s4tj|�tj||B���ntj|�tj||�@���d�S�)NZ FD_CLOEXECr���)r����r����ZF_GETFDZF_SETFD)r����ZinheritableZcloexec_flag�oldr���r���r����_set_inheritable���s ����r����c���������������@���s���e�Zd�Zdd��ZdS�)rW���c������� ��� ���K���sv���d�}|t�jkr*|�jj��\}}t|j��d��t�j|f||||d|d�|��|�_|d�k rr|j���t |j ��d|d�|�j_d�S�)NF)r[���r\���r]���r^���Zuniversal_newlinesr_����wb)� buffering)� subprocess�PIPEr����r#���r����r7����Popen�_procr%���r�����detachr\���) r���rB���r[���r\���r]���r^���r_���r`���Zstdin_wr���r���r����_start���s���� z_UnixSubprocessTransport._startN)r����r����r����r����r���r���r���r���rW������s���rW���c���������������@���s@���e�Zd�ZdZdd��Zdd��Zdd��Zdd ��Zd d��Zdd ��Z dS�)r���aH��Abstract 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. c�������������G���s ���t����dS�)a��Register 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)r���re���rA���rB���r���r���r���rX������s���� z&AbstractChildWatcher.add_child_handlerc�������������C���s ���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����)r���re���r���r���r����remove_child_handler���s����z)AbstractChildWatcher.remove_child_handlerc�������������C���s ���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����)r���r����r���r���r����attach_loop���s����z AbstractChildWatcher.attach_loopc�������������C���s ���t����dS�)zlClose the watcher. This must be called to make sure that any underlying resource is freed. N)r����)r���r���r���r���r%������s����zAbstractChildWatcher.closec�������������C���s ���t����dS�)zdEnter the watcher's context and allow starting new processes This function must return selfN)r����)r���r���r���r���� __enter__��s����zAbstractChildWatcher.__enter__c�������������C���s ���t����dS�)zExit the watcher's contextN)r����)r����a�b�cr���r���r����__exit__ ��s����zAbstractChildWatcher.__exit__N) r����r����r����r����rX���r����r����r%���r����r����r���r���r���r���r������s��� c���������������@���sD���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z dS�)�BaseChildWatcherc�������������C���s���d�|�_�i�|�_d�S�)N)r����� _callbacks)r���r���r���r���r�����s����zBaseChildWatcher.__init__c�������������C���s���|�j�d���d�S�)N)r����)r���r���r���r���r%�����s����zBaseChildWatcher.closec�������������C���s ���t����d�S�)N)r����)r����expected_pidr���r���r����_do_waitpid��s����zBaseChildWatcher._do_waitpidc�������������C���s ���t����d�S�)N)r����)r���r���r���r����_do_waitpid_all��s����z BaseChildWatcher._do_waitpid_allc�������������C���sf���|�j�d�k r$|d�kr$|�jr$tjdt��|�j�d�k r<|�j�jtj��||�_�|d�k rb|jtj|�j ��|�j ���d�S�)NzCA loop is being detached from a child watcher with pending handlers)r����r����r*���r+����RuntimeWarningr)���r5����SIGCHLDrE���� _sig_chldr����)r���r����r���r���r���r������s���� zBaseChildWatcher.attach_loopc�������������C���sF���y|�j����W�n4�tk r@�}�z|�jjd|d���W�Y�d�d�}~X�nX�d�S�)Nz$Unknown exception in SIGCHLD handler)r����r����)r����rZ���r����r����)r���rC���r���r���r���r����1��s����zBaseChildWatcher._sig_chldc�������������C���s2���t�j|�rt�j|��S�t�j|�r*t�j|�S�|S�d�S�)N)rz����WIFSIGNALED�WTERMSIG� WIFEXITED�WEXITSTATUS)r����statusr���r���r����_compute_returncode=��s ���� z$BaseChildWatcher._compute_returncodeN) r����r����r����r���r%���r����r����r����r����r����r���r���r���r���r������s���r����c�������������������sP���e�Zd�ZdZ��fdd�Zdd��Zdd��Zdd ��Zd d��Zdd ��Z dd��Z ���ZS�)r���ad��'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) c����������������s���|�j�j���t��j���d�S�)N)r����r-���r���r%���)r���)r!���r���r���r%���V��s���� zSafeChildWatcher.closec�������������C���s���|�S�)Nr���)r���r���r���r���r����Z��s����zSafeChildWatcher.__enter__c�������������C���s���d�S�)Nr���)r���r����r����r����r���r���r���r����]��s����zSafeChildWatcher.__exit__c�������������G���s.���|�j�d�krtd��||f|�j|<�|�j|��d�S�)NzICannot add child handler, the child watcher does not have a loop attached)r����r:���r����r����)r���re���rA���rB���r���r���r���rX���`��s ���� z"SafeChildWatcher.add_child_handlerc�������������C���s&���y|�j�|=�dS��tk r ���dS�X�d�S�)NTF)r����rG���)r���re���r���r���r���r����k��s ����z%SafeChildWatcher.remove_child_handlerc�������������C���s"���xt�|�j�D�]}|�j|��qW�d�S�)N)r(���r����r����)r���re���r���r���r���r����r��s����z SafeChildWatcher._do_waitpid_allc�������������C���s����yt�j|t�j�\}}W�n(�tk r>���|}d}tjd|��Y�n0X�|dkrLd�S�|�j|�}|�jj��rntj d||��y|�j j|�\}}W�n.�tk r����|�jj��r�tjd|dd��Y�nX�|||f|����d�S�)N����z8Unknown child process pid %d, will report returncode 255r���z$process %s exited with returncode %sz'Child watcher got an unexpected pid: %rT)r����) rz����waitpid�WNOHANG�ChildProcessErrorr���r����r����r����r����r����r�����poprG���)r���r����re���r����rf���rA���rB���r���r���r���r����w��s*���� zSafeChildWatcher._do_waitpid)r����r����r����r����r%���r����r����rX���r����r����r����r����r���r���)r!���r���r���K��s��� c�������������������sT���e�Zd�ZdZ��fdd�Z��fdd�Zdd��Zdd ��Zd d��Zdd ��Z dd��Z ���ZS�)r���aW��'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). c����������������s$���t���j���tj��|�_i�|�_d|�_d�S�)Nr���)r���r���� threadingZLock�_lock�_zombies�_forks)r���)r!���r���r���r������s���� zFastChildWatcher.__init__c����������������s"���|�j�j���|�jj���t��j���d�S�)N)r����r-���r����r���r%���)r���)r!���r���r���r%������s���� zFastChildWatcher.closec���������� ���C���s$���|�j���|��jd7��_|�S�Q�R�X�d�S�)Nr���)r����r����)r���r���r���r���r�������s����zFastChildWatcher.__enter__c���������� ���C���sV���|�j��:�|��jd8��_|�js$|�j�r(d�S�t|�j�}|�jj���W�d�Q�R�X�tjd|��d�S�)Nr���z5Caught subprocesses termination from unknown pids: %s)r����r����r����r;���r-���r���r����)r���r����r����r����Zcollateral_victimsr���r���r���r�������s���� zFastChildWatcher.__exit__c�������������G���sl���|�j�d�krtd��|�j�:�y|�jj|�}W�n"�tk rL���||f|�j|<�d�S�X�W�d�Q�R�X�|||f|����d�S�)NzICannot add child handler, the child watcher does not have a loop attached)r����r:���r����r����r����rG���r����)r���re���rA���rB���rf���r���r���r���rX������s���� z"FastChildWatcher.add_child_handlerc�������������C���s&���y|�j�|=�dS��tk r ���dS�X�d�S�)NTF)r����rG���)r���re���r���r���r���r�������s ����z%FastChildWatcher.remove_child_handlerc�������������C���s����x�yt�jdt�j�\}}W�n�tk r,���d�S�X�|dkr:d�S�|�j|�}|�j�v�y|�jj|�\}}W�nB�tk r����|�j r�||�j |<�|�jj��r�t jd||��wd�}Y�nX�|�jj��r�t jd||��W�d�Q�R�X�|d�kr�t jd||��q|||f|����qW�d�S�)Nr���r���z,unknown process %s exited with returncode %sz$process %s exited with returncode %sz8Caught subprocess termination from unknown pid: %d -> %dr2���)rz���r����r����r����r����r����r����r����rG���r����r����r����r����r���r����r����)r���re���r����rf���rA���rB���r���r���r���r�������s6���� z FastChildWatcher._do_waitpid_all)r����r����r����r����r���r%���r����r����rX���r����r����r����r���r���)r!���r���r������s��� c�������������������sH���e�Zd�ZdZeZ��fdd�Zdd��Z��fdd�Zdd ��Z d d��Z ���ZS�)�_UnixDefaultEventLoopPolicyz:UNIX event loop policy with a watcher for child processes.c����������������s���t���j���d�|�_d�S�)N)r���r����_watcher)r���)r!���r���r���r�����s���� z$_UnixDefaultEventLoopPolicy.__init__c���������� ���C���sH���t�j�8�|�jd�kr:t��|�_ttj��tj�r:|�jj|�j j ��W�d�Q�R�X�d�S�)N)r���r����r����r���rK���r�����current_thread�_MainThreadr�����_localr����)r���r���r���r���� _init_watcher��s���� z)_UnixDefaultEventLoopPolicy._init_watcherc����������������s6���t���j|��|�jdk r2ttj��tj�r2|�jj|��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_loopr����rK���r����r����r���r����)r���r����)r!���r���r���r����s���� z*_UnixDefaultEventLoopPolicy.set_event_loopc�������������C���s���|�j�dkr|�j���|�j�S�)zzGet the watcher for child processes. If not yet set, a SafeChildWatcher object is automatically created. N)r����r��)r���r���r���r���rV���&��s���� z-_UnixDefaultEventLoopPolicy.get_child_watcherc�������������C���s���|�j�dk r|�j�j���||�_�dS�)z$Set the watcher for child processes.N)r����r%���)r���ra���r���r���r����set_child_watcher0��s���� z-_UnixDefaultEventLoopPolicy.set_child_watcher)r����r����r����r����r���Z _loop_factoryr���r��r��rV���r��r����r���r���)r!���r���r������s��� r����)5r����r>���rz���r5���r"���rx���r����r&���r����r*�����r���r���r���r���r���r���r ���r ���r���r���r ����logr����__all__r�����ImportErrorr����fspathrw����AttributeErrorZBaseSelectorEventLoopr����hasattrr����r����Z ReadTransportrN���Z_FlowControlMixinZWriteTransportrT���r����r����ZBaseSubprocessTransportrW���r���r����r���r���ZBaseDefaultEventLoopPolicyr����r���r���r���r���r���r����<module>���sn��� �� ��O F=On2