관리-도구
편집 파일: unix_events.cpython-39.opt-2.pyc
a �����DOg*�����������������������@���s���d�dl�Z�d�dlZd�dlZd�dlZd�dlZd�dlZd�dlZd�dlZd�dlZd�dl Z d�dl Z d�dlZddlm Z �ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�dd lmZ�dd lmZ�ddlmZ�ddlmZ�dd lmZ�dZe jdkr�ed��dd��ZG�dd��dej�ZG�dd��dej�Z G�dd��dej!ej"�Z#G�dd��dej$�Z%G�dd��d�Z&G�dd��de&�Z'dd ��Z(G�d!d"��d"e&�Z)G�d#d$��d$e)�Z*G�d%d&��d&e)�Z+G�d'd(��d(e&�Z,G�d)d*��d*e&�Z-G�d+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�DefaultEventLoopPolicy�win32z+Signals are not really supported on Windowsc�����������������C���s���d�S��N��)�signum�framer���r����+/usr/lib64/python3.9/asyncio/unix_events.py�_sighandler_noop*���s����r���c�����������������������s����e�Zd�Zd(��fdd� Z��fdd�Zdd��Zdd ��Zd d��Zdd ��Zdd��Z d)dd�Z d*dd�Zd+dd�Zdd��Z d,ddddd�dd�Zd-dddddd�dd�Zd d!��Zd"d#��Zd$d%��Zd&d'��Z���ZS�).�_UnixSelectorEventLoopNc��������������������s���t����|��i�|�_d�S�r���)�super�__init__�_signal_handlers)�self�selector�� __class__r���r���r���5���s����z_UnixSelectorEventLoop.__init__c��������������������sZ���t�������t���s.t|�j�D�]}|��|��qn(|�jrVtjd|��d�t |�d��|�j� ���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!����sigr#���r���r���r'���9���s���� �z_UnixSelectorEventLoop.closec�����������������C���s���|D�]}|sq|���|��qd�S�r���)�_handle_signal)r!����datar���r���r���r����_process_self_dataG���s����z)_UnixSelectorEventLoop._process_self_datac�������������� ���G���sR��t��|�st��|�rtd��|��|��|�����zt�|�j� ����W�n4�t tfyv�}�ztt |���W�Y�d�}~n d�}~0�0�t�|||�d��}||�j|<�zt�|t��t�|d��W�n��t�yL�}�z�|�j|=�|�j�szt�d��W�n6�t tf�y�}�zt�d|��W�Y�d�}~n d�}~0�0�|jtjk�r6td|��d���n��W�Y�d�}~n d�}~0�0�d�S�)Nz3coroutines cannot be used with add_signal_handler()F����set_wakeup_fd(-1) failed: %s�sig � cannot be caught)r���ZiscoroutineZiscoroutinefunction� TypeError� _check_signal� _check_closed�signal� set_wakeup_fdZ_csock�fileno� ValueError�OSError�RuntimeError�strr����Handler ���r����siginterruptr ����info�errno�EINVAL)r!���r1����callback�args�exc�handleZnexcr���r���r����add_signal_handlerN���s2���� � " "z)_UnixSelectorEventLoop.add_signal_handlerc�����������������C���s8���|�j��|�}|d�u�rd�S�|jr*|��|��n |��|��d�S�r���)r ����getZ _cancelledr+���Z_add_callback_signalsafe)r!���r1���rK���r���r���r���r2���{���s����z%_UnixSelectorEventLoop._handle_signalc�������������� ���C���s����|���|��z|�j|=�W�n�ty*���Y�dS�0�|tjkr>tj}ntj}zt�||��W�nD�ty��}�z,|jtj kr�t d|��d���n��W�Y�d�}~n d�}~0�0�|�js�zt�d��W�n4�ttfy��}�zt �d|��W�Y�d�}~n d�}~0�0�dS�)NFr7���r8���r5���r6���T)r:���r ����KeyErrorr<����SIGINT�default_int_handler�SIG_DFLr@���rF���rG���rA���r=���r?���r ���rE���)r!���r1����handlerrJ���r���r���r���r+�������s(���� "z,_UnixSelectorEventLoop.remove_signal_handlerc�����������������C���s6���t�|t�std|����|t���vr2td|�����d�S�)Nzsig must be an int, not zinvalid signal number )� isinstance�intr9���r<���� valid_signalsr?���r0���r���r���r���r:�������s���� z$_UnixSelectorEventLoop._check_signalc�����������������C���s���t�|�||||�S�r���)�_UnixReadPipeTransport�r!����pipe�protocol�waiter�extrar���r���r����_make_read_pipe_transport����s����z0_UnixSelectorEventLoop._make_read_pipe_transportc�����������������C���s���t�|�||||�S�r���)�_UnixWritePipeTransportrW���r���r���r����_make_write_pipe_transport����s����z1_UnixSelectorEventLoop._make_write_pipe_transportc ����������� ��� �������s����t������} | ���std��|����}t|�|||||||f||d�| ��}| �|���|�j|��z|I�d�H��W�n@�t t fy������Y�n*�ty����|����|� ��I�d�H����Y�n0�W�d�����n1�s�0����Y��|S�)NzRasyncio.get_child_watcher() is not activated, subprocess support is not installed.)rZ���r[���)r����get_child_watcher� is_activerA���� create_future�_UnixSubprocessTransport�add_child_handlerZget_pid�_child_watcher_callback� SystemExit�KeyboardInterrupt� BaseExceptionr'����_wait) r!���rY���rI����shell�stdin�stdout�stderr�bufsizer[����kwargs�watcherrZ����transpr���r���r����_make_subprocess_transport����s.���� ��� �&z1_UnixSelectorEventLoop._make_subprocess_transportc�����������������C���s���|���|j|��d�S�r���)�call_soon_threadsafeZ_process_exited)r!����pid� returncoderp���r���r���r���rd�������s����z._UnixSelectorEventLoop._child_watcher_callback)�ssl�sock�server_hostname�ssl_handshake_timeoutc���������� ����������s ��|r|d�u�r6t�d��n |d�ur&t�d��|d�ur6t�d��|d�ur�|d�urNt�d��t�|�}t�tjtjd�}z |�d��|��||�I�d�H��W�q����|������Y�q�0�n@|d�u�r�t�d��|j tjks�|j tjkr�t�d|����|�d��|�j|||||d �I�d�H�\}}||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 timer���Fzno path and sock were specified�.A UNIX Domain Stream Socket was expected, got )rx���)r?����os�fspath�socket�AF_UNIX�SOCK_STREAM�setblockingZsock_connectr'����family�typeZ_create_connection_transport) r!����protocol_factory�pathru���rv���rw���rx���� transportrY���r���r���r����create_unix_connection����sL������� �� �z-_UnixSelectorEventLoop.create_unix_connection�d���T)rv����backlogru���rx���� start_servingc������������� �������s���t�|t�rtd��|d�ur&|s&td��|d�u�rJ|d�ur@td��t�|�}t�tjtj�}|d�dvr�z t � t� |�j�r�t�|��W�nB�t y����Y�n2�ty��}�zt�d||��W�Y�d�}~n d�}~0�0�z|�|��W�nn�t�y2�} �z@|����| jtjk�rd|�d�} ttj| �d��n��W�Y�d�} ~ nd�} ~ 0����|������Y�n0�n<|d�u��r\td ��|jtjk�sx|jtjk�r�td |����|�d��t�|�|g||||�}|�r�|����t�d�I�d�H��|S�)Nz*ssl argument must be an SSLContext or Nonery���rz���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)rS����boolr9���r?���r|���r}���r~���r���r�����stat�S_ISSOCK�st_mode�remove�FileNotFoundErrorr@���r ����error�bindr'���rF���Z EADDRINUSEr����r����r����r���ZServerZ_start_servingr����sleep)r!���r����r����rv���r����ru���rx���r�����errrJ����msgZserverr���r���r����create_unix_server��sh���� � � � � �� �z)_UnixSelectorEventLoop.create_unix_serverc����������� ��� �������s����z t�j�W�n�ty&���t�d��Y�n0�z|���}W�n4�ttjfyh�}�zt�d��W�Y�d�}~n d�}~0�0�zt��|�j }W�n�t y����t�d��Y�n0�|r�|n|}|s�dS�|����} |��| d�|||||d��| I�d�H�S�)Nzos.sendfile() is not availableznot a regular filer���) r|����sendfile�AttributeErrorr����SendfileNotAvailableErrorr>����io�UnsupportedOperation�fstat�st_sizer@���ra����_sock_sendfile_native_impl) r!���rv����file�offset�countr>���r�����fsize� blocksize�futr���r���r����_sock_sendfile_nativeJ��s,���� � �z,_UnixSelectorEventLoop._sock_sendfile_nativec �����������������C���s,��|����} |d�ur|��|��|���r4|��|||��d�S�|rd||�}|dkrd|��|||��|�|��d�S�zt�| |||�} W��nD�ttfy����|d�u�r�|�� ||��|�� | |�j|| ||||||� �Y��nd�t�yj�}�z�|d�u�r|j t jk�rt|�tu�rtdt j�}||_|}|dk�r>t�d�} |��|||��|�| ��n|��|||��|�|��W�Y�d�}~n�d�}~0��ttf�y������Y�n��t�y��}�z$|��|||��|�|��W�Y�d�}~nrd�}~0�0�| dk�r�|��|||��|�|��nD|| 7�}|| 7�}|d�u��r |�� ||��|�� | |�j|| ||||||� �d�S�)Nr���zsocket is not connectedzos.sendfile call failed)r>���� remove_writer� cancelled�_sock_sendfile_update_filepos� set_resultr|���r�����BlockingIOError�InterruptedError�_sock_add_cancellation_callbackZ add_writerr����r@���rF���ZENOTCONNr�����ConnectionError� __cause__r���r����� set_exceptionre���rf���rg���)r!���r����Z registered_fdrv���r>���r����r����r����� total_sent�fd�sentrJ����new_excr����r���r���r���r����a��sp���� � � �� � �z1_UnixSelectorEventLoop._sock_sendfile_native_implc�����������������C���s���|dkrt��||t�j��d�S��Nr���)r|����lseek�SEEK_SET)r!���r>���r����r����r���r���r���r�������s����z4_UnixSelectorEventLoop._sock_sendfile_update_fileposc��������������������s������fdd�}|��|��d�S�)Nc��������������������s&���|�����r"����}|dkr"���|��d�S�)Nr5���)r����r>���r����)r����r�����r!���rv���r���r����cb���s����zB_UnixSelectorEventLoop._sock_add_cancellation_callback.<locals>.cb)�add_done_callback)r!���r����rv���r����r���r����r���r�������s����z6_UnixSelectorEventLoop._sock_add_cancellation_callback)N)NN)NN)N)N)N)�__name__� __module__�__qualname__r���r'���r4���rL���r2���r+���r:���r\���r^���rq���rd���r����r����r����r����r����r����� __classcell__r���r���r#���r���r���/���s@���- ��� ��� �� ���.���CFr���c�����������������������s����e�Zd�ZdZd��fdd� Zdd��Zdd��Zd d ��Zdd��Zd d��Z dd��Z dd��Zdd��Ze jfdd�Zddd�Zdd��Zdd��Z���ZS�) rV���i���Nc��������������������s����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��|d�ur�|�j�tj|d���d�S�)NrX���Fz)Pipe transport is for pipes/sockets only.)r���r����_extra�_loop�_piper>����_fileno� _protocol�_closing�_pausedr|���r����r����r�����S_ISFIFOr�����S_ISCHRr?����set_blocking� call_soon�connection_made�_add_reader�_read_readyr ����_set_result_unless_cancelled)r!����looprX���rY���rZ���r[����moder#���r���r���r������s6���� ��� �z_UnixReadPipeTransport.__init__c�����������������C���s����|�j�jg}|�jd�u�r |�d��n|�jr0|�d��|�d|�j�����t|�jdd��}|�jd�ur�|d�ur�t� ||�jt j�}|r�|�d��q�|�d��n |�jd�ur�|�d��n |�d��d�d � |��S�) N�closed�closing�fd=� _selector�polling�idle�open�<{}>� )r$���r����r�����appendr����r�����getattrr����r ����_test_selector_event� selectors� EVENT_READ�format�join)r!���rE���r"���r����r���r���r����__repr__���s$���� � z_UnixReadPipeTransport.__repr__c�������������� ���C���s����zt��|�j|�j�}W�nD�ttfy*���Y�n��tyX�}�z|��|d��W�Y�d�}~nfd�}~0�0�|rl|�j� |��nJ|�j ���r�t� d|���d|�_|�j �|�j��|�j �|�jj��|�j �|�jd���d�S�)Nz"Fatal read error on pipe transport�%r was closed by peerT)r|����readr�����max_sizer����r����r@����_fatal_errorr����Z data_receivedr����� get_debugr ���rE���r�����_remove_readerr����Zeof_received�_call_connection_lost)r!���r3���rJ���r���r���r���r�������s����" z"_UnixReadPipeTransport._read_readyc�����������������C���s>���|�j�s|�jrd�S�d|�_|�j�|�j��|�j���r:t�d|���d�S�)NTz%r pauses reading)r����r����r����r����r����r����r ����debug�r!���r���r���r���� pause_reading���s���� z$_UnixReadPipeTransport.pause_readingc�����������������C���sB���|�j�s|�jsd�S�d|�_|�j�|�j|�j��|�j���r>t�d|���d�S�)NFz%r resumes reading) r����r����r����r����r����r����r����r ���r����r����r���r���r����resume_reading��s���� z%_UnixReadPipeTransport.resume_readingc�����������������C���s ���||�_�d�S�r����r�����r!���rY���r���r���r����set_protocol ��s����z#_UnixReadPipeTransport.set_protocolc�����������������C���s���|�j�S�r���r����r����r���r���r����get_protocol��s����z#_UnixReadPipeTransport.get_protocolc�����������������C���s���|�j�S�r����r����r����r���r���r���� is_closing��s����z!_UnixReadPipeTransport.is_closingc�����������������C���s���|�j�s|��d���d�S�r���)r�����_closer����r���r���r���r'�����s����z_UnixReadPipeTransport.closec�����������������C���s,���|�j�d�ur(|d|���t|�d��|�j�����d�S��Nzunclosed transport r%����r����r.���r'����r!����_warnr���r���r����__del__��s���� z_UnixReadPipeTransport.__del__�Fatal error on pipe transportc�����������������C���sZ���t�|t�r4|jtjkr4|�j���rLtjd|�|dd��n|�j�|||�|�j d���|�� |��d�S��Nz%r: %sT��exc_info)�message� exceptionr����rY���)rS���r@���rF���ZEIOr����r����r ���r�����call_exception_handlerr����r�����r!���rJ���r����r���r���r���r������s���� �z#_UnixReadPipeTransport._fatal_errorc�����������������C���s(���d|�_�|�j�|�j��|�j�|�j|��d�S��NT)r����r����r����r����r����r�����r!���rJ���r���r���r���r����-��s����z_UnixReadPipeTransport._closec�����������������C���sP���z,|�j��|��W�|�j����d�|�_d�|�_�d�|�_n|�j����d�|�_d�|�_�d�|�_0�d�S�r����r����Zconnection_lostr����r'���r����r��r���r���r���r����2��s���� � z,_UnixReadPipeTransport._call_connection_lost)NN)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���rV������s��� rV���c�����������������������s����e�Zd�Zd%��fdd� Zdd��Zdd��Zdd ��Zd d��Zdd ��Zdd��Z dd��Z dd��Zdd��Zdd��Z dd��Zejfdd�Zdd��Zd&dd �Zd'd!d"�Zd#d$��Z���ZS�)(r]���Nc����������� ���������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��|d�ur�|�j�tj|d���d�S�)NrX���r���Fz?Pipe transport is only for pipes, sockets and character devicesZaix)r���r���r����r����r>���r����r����� bytearray�_buffer� _conn_lostr����r|���r����r����r����r����r����r����r?���r����r����r����r����r(����platform� startswithr����r����r ���r����) r!���r����rX���rY���rZ���r[���r����Zis_char�is_fifo� is_socketr#���r���r���r���?��s6���� � �z _UnixWritePipeTransport.__init__c�����������������C���s����|�j�jg}|�jd�u�r |�d��n|�jr0|�d��|�d|�j�����t|�jdd��}|�jd�ur�|d�ur�t� ||�jt j�}|r�|�d��n |�d��|����}|�d|�����n |�jd�ur�|�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�����EVENT_WRITE�get_write_buffer_sizer����r����)r!���rE���r"���r����rm���r���r���r���r����d��s(���� � z _UnixWritePipeTransport.__repr__c�����������������C���s ���t�|�j�S�r���)�lenr��r����r���r���r���r��|��s����z-_UnixWritePipeTransport.get_write_buffer_sizec�����������������C���s6���|�j����rt�d|���|�jr*|��t����n|�����d�S�)Nr����)r����r����r ���rE���r��r�����BrokenPipeErrorr����r���r���r���r������s ���� z#_UnixWritePipeTransport._read_readyc�������������� ���C���s.��t�|t�rt|�}|sd�S�|�js&|�jrN|�jtjkr<t�d��|��jd7��_d�S�|�j �szt �|�j|�}W�nn�t tfy����d}Y�nV�ttfy������Y�n@�ty��}�z(|��jd7��_|��|d��W�Y�d�}~d�S�d�}~0�0�|t|�kr�d�S�|dk�rt|�|d���}|�j�|�j|�j��|��j |7��_ |�����d�S�)Nz=pipe closed by peer or os.write(pipe, data) raised exception.r���r����#Fatal write error on pipe transport)rS���r��� memoryviewr��r����r���Z!LOG_THRESHOLD_FOR_CONNLOST_WRITESr ����warningr��r|����writer����r����r����re���rf���rg���r����r��r����Z_add_writer�_write_readyZ_maybe_pause_protocol)r!���r3����nrJ���r���r���r���r�����s6���� z_UnixWritePipeTransport.writec�������������� ���C���s����zt��|�j|�j�}W�n��ttfy*���Y�n��ttfy@�����Y�n��ty��}�z>|�j� ���|��j d7��_ |�j�|�j��|�� |d��W�Y�d�}~nnd�}~0�0�|t|�j�kr�|�j� ���|�j�|�j��|�����|�jr�|�j�|�j��|��d���d�S�|dkr�|�jd�|�=�d�S�)Nr���r��r���)r|���r��r����r��r����r����re���rf���rg���r/���r��r�����_remove_writerr����r��Z_maybe_resume_protocolr����r����r����)r!���r��rJ���r���r���r���r�����s*���� " z$_UnixWritePipeTransport._write_readyc�����������������C���s���dS�r���r���r����r���r���r���� can_write_eof���s����z%_UnixWritePipeTransport.can_write_eofc�����������������C���s8���|�j�r d�S�d|�_�|�js4|�j�|�j��|�j�|�jd���d�S�r���)r����r��r����r����r����r����r����r����r���r���r���� write_eof���s����z!_UnixWritePipeTransport.write_eofc�����������������C���s ���||�_�d�S�r���r����r����r���r���r���r�������s����z$_UnixWritePipeTransport.set_protocolc�����������������C���s���|�j�S�r���r����r����r���r���r���r�������s����z$_UnixWritePipeTransport.get_protocolc�����������������C���s���|�j�S�r���r����r����r���r���r���r�������s����z"_UnixWritePipeTransport.is_closingc�����������������C���s���|�j�d�ur|�js|�����d�S�r���)r����r����r��r����r���r���r���r'������s����z_UnixWritePipeTransport.closec�����������������C���s,���|�j�d�ur(|d|���t|�d��|�j�����d�S�r����r����r����r���r���r���r�������s���� z_UnixWritePipeTransport.__del__c�����������������C���s���|���d���d�S�r���)r����r����r���r���r����abort���s����z_UnixWritePipeTransport.abortr����c�����������������C���sN���t�|t�r(|�j���r@tjd|�|dd��n|�j�|||�|�jd���|��|��d�S�r����) rS���r@���r����r����r ���r����r����r����r����r����r���r���r���r�������s���� �z$_UnixWritePipeTransport._fatal_errorc�����������������C���sF���d|�_�|�jr|�j�|�j��|�j����|�j�|�j��|�j�|�j|��d�S�r���) r����r��r����r��r����r/���r����r����r����r��r���r���r���r�������s���� z_UnixWritePipeTransport._closec�����������������C���sP���z,|�j��|��W�|�j����d�|�_d�|�_�d�|�_n|�j����d�|�_d�|�_�d�|�_0�d�S�r���r��r��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���r]���<��s"���% # r]���c�������������������@���s���e�Zd�Zdd��ZdS�)rb���c����������� ��� ���K���s����d�}|t�jkrt���\}}zht�j|f||||d|d�|��|�_|d�urh|����t|���d|d�|�j_ d�}W�|d�ur�|����|����n|d�ur�|����|����0�d�S�)NF)ri���rj���rk���rl����universal_newlinesrm����wb)� buffering) � subprocess�PIPEr~���� socketpair�Popen�_procr'���r�����detachrj���) r!���rI���ri���rj���rk���rl���rm���rn���Zstdin_wr���r���r����_start��s,���� ��� �z_UnixSubprocessTransport._startN)r����r����r����r!��r���r���r���r���rb��� ��s���rb���c�������������������@���sD���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z dS�)r���c�����������������G���s ���t����d�S�r�����NotImplementedError�r!���rs���rH���rI���r���r���r���rc���9��s���� z&AbstractChildWatcher.add_child_handlerc�����������������C���s ���t����d�S�r���r"���r!���rs���r���r���r����remove_child_handlerD��s����z)AbstractChildWatcher.remove_child_handlerc�����������������C���s ���t����d�S�r���r"���r!���r����r���r���r����attach_loopL��s����z AbstractChildWatcher.attach_loopc�����������������C���s ���t����d�S�r���r"��r����r���r���r���r'���V��s����zAbstractChildWatcher.closec�����������������C���s ���t����d�S�r���r"��r����r���r���r���r`���]��s����zAbstractChildWatcher.is_activec�����������������C���s ���t����d�S�r���r"��r����r���r���r���� __enter__f��s����zAbstractChildWatcher.__enter__c�����������������C���s ���t����d�S�r���r"���r!����a�b�cr���r���r����__exit__l��s����zAbstractChildWatcher.__exit__N) r����r����r����rc���r&��r(��r'���r`���r)��r.��r���r���r���r���r���"��s��� r���c�������������������@���sT���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z dd��Z dd��ZdS�)r���c�����������������C���s���d�|�_�i�|�_d�S�r����r����� _callbacksr����r���r���r���r���}��s����zPidfdChildWatcher.__init__c�����������������C���s���|�S�r���r���r����r���r���r���r)�����s����zPidfdChildWatcher.__enter__c�����������������C���s���d�S�r���r���)r!����exc_type� exc_value� exc_tracebackr���r���r���r.�����s����zPidfdChildWatcher.__exit__c�����������������C���s���|�j�d�uo|�j����S�r����r����Z is_runningr����r���r���r���r`������s����zPidfdChildWatcher.is_activec�����������������C���s���|���d���d�S�r����r(��r����r���r���r���r'������s����zPidfdChildWatcher.closec�����������������C���sd���|�j�d�ur$|d�u�r$|�jr$t�dt��|�j���D�] \}}}|�j��|��t�|��q.|�j� ���||�_�d�S��NzCA loop is being detached from a child watcher with pending handlers) r����r0��r,���r-����RuntimeWarning�valuesr����r|���r'���r/���)r!���r�����pidfd�_r���r���r���r(�����s����� zPidfdChildWatcher.attach_loopc�����������������G���sZ���|�j��|�}|d�ur*|d�||f|�j�|<�n,t�|�}|�j�||�j|��|||f|�j�|<�d�S�r����)r0��rM���r|���� pidfd_openr����r�����_do_wait)r!���rs���rH���rI����existingr9��r���r���r���rc������s���� z#PidfdChildWatcher.add_child_handlerc�����������������C���s~���|�j��|�\}}}|�j�|��zt�|d�\}}W�n"�tyT���d}t�d|��Y�n 0�t |�}t� |��|||g|�R����d�S�)Nr�������zJchild process pid %d exit status already read: will report returncode 255)r0���popr����r����r|����waitpid�ChildProcessErrorr ���r���_compute_returncoder'���)r!���rs���r9��rH���rI���r:���statusrt���r���r���r���r<�����s����� zPidfdChildWatcher._do_waitc�����������������C���sF���z|�j��|�\}}}W�n�ty*���Y�dS�0�|�j�|��t�|��dS�)NFT)r0��r?��rN���r����r����r|���r'���)r!���rs���r9��r:��r���r���r���r&�����s���� z&PidfdChildWatcher.remove_child_handlerN)r����r����r����r���r)��r.��r`���r'���r(��rc���r<��r&��r���r���r���r���r���q��s��� r���c�����������������C���s2���t��|��rt��|���S�t��|��r*t��|��S�|�S�d�S�r���)r|����WIFSIGNALED�WTERMSIG� WIFEXITED�WEXITSTATUS)rC��r���r���r���rB�����s ���� rB��c�������������������@���sD���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z dS�)�BaseChildWatcherc�����������������C���s���d�|�_�i�|�_d�S�r���r/��r����r���r���r���r������s����zBaseChildWatcher.__init__c�����������������C���s���|���d���d�S�r���r5��r����r���r���r���r'������s����zBaseChildWatcher.closec�����������������C���s���|�j�d�uo|�j����S�r���r4��r����r���r���r���r`������s����zBaseChildWatcher.is_activec�����������������C���s ���t����d�S�r���r"��)r!����expected_pidr���r���r����_do_waitpid���s����zBaseChildWatcher._do_waitpidc�����������������C���s ���t����d�S�r���r"��r����r���r���r����_do_waitpid_all���s����z BaseChildWatcher._do_waitpid_allc�����������������C���sf���|�j�d�ur$|d�u�r$|�jr$t�dt��|�j�d�ur<|�j��tj��||�_�|d�urb|�tj|�j ��|�� ���d�S�r6��)r����r0��r,���r-���r7��r+���r<����SIGCHLDrL���� _sig_chldrK��r'��r���r���r���r(�����s����� zBaseChildWatcher.attach_loopc�������������� ���C���s^���z|������W�nL�ttfy$�����Y�n6�tyX�}�z|�j�d|d���W�Y�d�}~n d�}~0�0�d�S�)N�$Unknown exception in SIGCHLD handler)r����r����)rK��re���rf���rg���r����r����r��r���r���r���rM�����s�����zBaseChildWatcher._sig_chldN) r����r����r����r���r'���r`���rJ��rK��r(��rM��r���r���r���r���rH�����s���rH��c�����������������������sL���e�Zd�Z��fdd�Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z ���Z S�)r���c��������������������s���|�j�����t������d�S�r���)r0��r/���r���r'���r����r#���r���r���r'��� ��s���� zSafeChildWatcher.closec�����������������C���s���|�S�r���r���r����r���r���r���r)����s����zSafeChildWatcher.__enter__c�����������������C���s���d�S�r���r���r*��r���r���r���r.����s����zSafeChildWatcher.__exit__c�����������������G���s���||f|�j�|<�|��|��d�S�r���)r0��rJ��r$��r���r���r���rc�����s����z"SafeChildWatcher.add_child_handlerc�����������������C���s(���z|�j�|=�W�dS��ty"���Y�dS�0�d�S��NTF�r0��rN���r%��r���r���r���r&����s ����z%SafeChildWatcher.remove_child_handlerc�����������������C���s���t�|�j�D�]}|��|��q d�S�r����r*���r0��rJ��r%��r���r���r���rK��$��s����z SafeChildWatcher._do_waitpid_allc�����������������C���s����zt��|t�j�\}}W�n&�ty<���|}d}t�d|��Y�n.0�|dkrJd�S�t|�}|�j���rjt� d||��z|�j �|�\}}W�n,�ty����|�j���r�tjd|dd��Y�n0�|||g|�R����d�S�)Nr>���8Unknown child process pid %d, will report returncode 255r����$process %s exited with returncode %s�'Child watcher got an unexpected pid: %rTr����) r|���r@���WNOHANGrA��r ���r��rB��r����r����r����r0��r?��rN���)r!���rI��rs���rC��rt���rH���rI���r���r���r���rJ��)��s0����� � �zSafeChildWatcher._do_waitpid)r����r����r����r'���r)��r.��rc���r&��rK��rJ��r����r���r���r#���r���r�����s���r���c�����������������������sP���e�Zd�Z��fdd�Z��fdd�Zdd��Zdd��Zd d ��Zdd��Zd d��Z ���Z S�)r���c��������������������s$���t�������t���|�_i�|�_d|�_d�S�r����)r���r���� threading�Lock�_lock�_zombies�_forksr����r#���r���r���r���V��s���� zFastChildWatcher.__init__c��������������������s"���|�j�����|�j����t������d�S�r���)r0��r/���rY��r���r'���r����r#���r���r���r'���\��s���� zFastChildWatcher.closec�����������������C���s<���|�j��"�|��jd7��_|�W��d�����S�1�s.0����Y��d�S�)Nr���)rX��rZ��r����r���r���r���r)��a��s����zFastChildWatcher.__enter__c�����������������C���st���|�j��N�|��jd8��_|�js"|�js2W�d�����d�S�t|�j�}|�j����W�d�����n1�sZ0����Y��t�d|��d�S�)Nr���z5Caught subprocesses termination from unknown pids: %s)rX��rZ��rY��rB���r/���r ���r��)r!���r+��r,��r-��Zcollateral_victimsr���r���r���r.��g��s���� (�zFastChildWatcher.__exit__c�������������� ���G���s|���|�j��P�z|�j�|�}W�n.�tyF���||f|�j|<�Y�W�d�����d�S�0�W�d�����n1�s\0����Y��|||g|�R����d�S�r���)rX��rY��r?��rN���r0��)r!���rs���rH���rI���rt���r���r���r���rc���u��s����2z"FastChildWatcher.add_child_handlerc�����������������C���s(���z|�j�|=�W�dS��ty"���Y�dS�0�d�S�rO��rP��r%��r���r���r���r&�����s ����z%FastChildWatcher.remove_child_handlerc�������������� ���C���s��zt��dt�j�\}}W�n�ty*���Y�d�S�0�|dkr8d�S�t|�}|�j���z|�j�|�\}}W�nN�ty����|�j r�||�j |<�|�j���r�t �d||��Y�W�d�����q�d�}Y�n0�|�j���r�t �d||��W�d�����n1�s�0����Y��|d�u�r�t �d||��q�|||g|�R����q�d�S�)Nr5���r���z,unknown process %s exited with returncode %srS��z8Caught subprocess termination from unknown pid: %d -> %d)r|���r@��rU��rA��rB��rX��r0��r?��rN���rZ��rY��r����r����r ���r����r��)r!���rs���rC��rt���rH���rI���r���r���r���rK�����s:���� � �"�z FastChildWatcher._do_waitpid_all)r����r����r����r���r'���r)��r.��rc���r&��rK��r����r���r���r#���r���r���L��s��� r���c�������������������@���sd���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z dd��Z dd��Zdd��Zdd��Z dS�)r���c�����������������C���s���i�|�_�d�|�_d�S�r���)r0���_saved_sighandlerr����r���r���r���r������s����zMultiLoopChildWatcher.__init__c�����������������C���s ���|�j�d�uS�r���)r[��r����r���r���r���r`������s����zMultiLoopChildWatcher.is_activec�����������������C���sT���|�j�����|�jd�u�rd�S�t�tj�}||�jkr:t�d��nt�tj|�j��d�|�_d�S�)Nz+SIGCHLD handler was changed by outside code) r0��r/���r[��r<���� getsignalrL��rM��r ���r��)r!���rR���r���r���r���r'������s���� zMultiLoopChildWatcher.closec�����������������C���s���|�S�r���r���r����r���r���r���r)�����s����zMultiLoopChildWatcher.__enter__c�����������������C���s���d�S�r���r����r!���r1���exc_val�exc_tbr���r���r���r.�����s����zMultiLoopChildWatcher.__exit__c�����������������G���s&���t����}|||f|�j|<�|��|��d�S�r���)r����get_running_loopr0��rJ��)r!���rs���rH���rI���r����r���r���r���rc������s����z'MultiLoopChildWatcher.add_child_handlerc�����������������C���s(���z|�j�|=�W�dS��ty"���Y�dS�0�d�S�rO��rP��r%��r���r���r���r&�����s ����z*MultiLoopChildWatcher.remove_child_handlerc�����������������C���sN���|�j�d�urd�S�t�tj|�j�|�_�|�j�d�u�r<t�d��tj|�_�t�tjd��d�S�)NzaPrevious SIGCHLD handler was set by non-Python code, restore to default handler on watcher close.F)r[��r<���rL��rM��r ���r��rQ���rD���r'��r���r���r���r(�����s���� z!MultiLoopChildWatcher.attach_loopc�����������������C���s���t�|�j�D�]}|��|��q d�S�r���rQ��r%��r���r���r���rK�����s����z%MultiLoopChildWatcher._do_waitpid_allc����������� ������C���s����zt��|t�j�\}}W�n*�ty@���|}d}t�d|��d}Y�n0�|dkrNd�S�t|�}d}z|�j�|�\}}}W�n"�t y����tjd|dd��Y�nJ0�|� ��r�t�d||��n0|r�|���r�t�d ||��|j |||g|�R����d�S�) Nr>��rR��Fr���TrT��r�����%Loop %r that handles pid %r is closedrS��)r|���r@��rU��rA��r ���r��rB��r0��r?��rN���� is_closedr����r����rr���) r!���rI��rs���rC��rt���Z debug_logr����rH���rI���r���r���r���rJ����s6����� ��z!MultiLoopChildWatcher._do_waitpidc�������������� ���C���sH���z|������W�n6�ttfy$�����Y�n �tyB���tjddd��Y�n0�d�S�)NrN��Tr����)rK��re���rf���rg���r ���r��)r!���r���r���r���r���r���rM��)��s����zMultiLoopChildWatcher._sig_chldN)r����r����r����r���r`���r'���r)��r.��rc���r&��r(��rK��rJ��rM��r���r���r���r���r������s���%r���c�������������������@���sj���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Ze j fd d�Zdd��Zdd��Z dd��Zdd��ZdS�)r���c�����������������C���s���t��d�|�_i�|�_d�S�r����)� itertoolsr�����_pid_counter�_threadsr����r���r���r���r���?��s����zThreadedChildWatcher.__init__c�����������������C���s���dS�r���r���r����r���r���r���r`���C��s����zThreadedChildWatcher.is_activec�����������������C���s���|������d�S�r���)� _join_threadsr����r���r���r���r'���F��s����zThreadedChildWatcher.closec�����������������C���s.���dd��t�|�j����D��}|D�]}|����qd�S�)Nc�����������������S���s���g�|�]}|����r|js|�qS�r���)�is_alive�daemon��.0�threadr���r���r���� <listcomp>K��s����z6ThreadedChildWatcher._join_threads.<locals>.<listcomp>)r*���re��r8��r����)r!����threadsrk��r���r���r���rf��I��s����z"ThreadedChildWatcher._join_threadsc�����������������C���s���|�S�r���r���r����r���r���r���r)��P��s����zThreadedChildWatcher.__enter__c�����������������C���s���d�S�r���r���r]��r���r���r���r.��S��s����zThreadedChildWatcher.__exit__c�����������������C���s6���dd��t�|�j����D��}|r2||�j��d�t|�d��d�S�)Nc�����������������S���s���g�|�]}|����r|�qS�r���)rg��ri��r���r���r���rl��W��s����z0ThreadedChildWatcher.__del__.<locals>.<listcomp>z0 has registered but not finished child processesr%���)r*���re��r8��r$���r.���)r!���r����rm��r���r���r���r����V��s�����zThreadedChildWatcher.__del__c�����������������G���sF���t����}tj|�jdt|�j����||||fdd�}||�j|<�|����d�S�)Nzwaitpid-T)�target�namerI���rh��) r���r`��rV���ThreadrJ���nextrd��re���start)r!���rs���rH���rI���r����rk��r���r���r���rc���^��s���� � z&ThreadedChildWatcher.add_child_handlerc�����������������C���s���dS�r���r���r%��r���r���r���r&��g��s����z)ThreadedChildWatcher.remove_child_handlerc�����������������C���s���d�S�r���r���r'��r���r���r���r(��m��s����z ThreadedChildWatcher.attach_loopc�����������������C���s����zt��|d�\}}W�n&�ty:���|}d}t�d|��Y�n 0�t|�}|���rZt�d||��|���rrt�d||��n|j |||g|�R����|�j �|��d�S�)Nr���r>��rR��rS��ra��)r|���r@��rA��r ���r��rB��r����r����rb��rr���re��r?��)r!���r����rI��rH���rI���rs���rC��rt���r���r���r���rJ��p��s$����� �z ThreadedChildWatcher._do_waitpidN)r����r����r����r���r`���r'���rf��r)��r.��r,���r-���r����rc���r&��r(��rJ��r���r���r���r���r���2��s��� r���c�����������������������sD���e�Zd�ZeZ��fdd�Zdd��Z��fdd�Zdd��Zd d ��Z ���Z S�)�_UnixDefaultEventLoopPolicyc��������������������s���t�������d�|�_d�S�r���)r���r����_watcherr����r#���r���r���r������s���� z$_UnixDefaultEventLoopPolicy.__init__c�����������������C���s\���t�j�B�|�jd�u�r:t��|�_t���t���u�r:|�j�|�jj ��W�d�����n1�sN0����Y��d�S�r���) r���rX��rt��r���rV���current_thread�main_threadr(���_localr����r����r���r���r���� _init_watcher���s ���� z)_UnixDefaultEventLoopPolicy._init_watcherc��������������������s6���t����|��|�jd�ur2t���t���u�r2|�j�|��d�S�r���)r����set_event_looprt��rV��ru��rv��r(��r'��r#���r���r���ry�����s ���� �z*_UnixDefaultEventLoopPolicy.set_event_loopc�����������������C���s���|�j�d�u�r|�����|�j�S�r���)rt��rx��r����r���r���r���r_������s���� z-_UnixDefaultEventLoopPolicy.get_child_watcherc�����������������C���s���|�j�d�ur|�j�����||�_�d�S�r���)rt��r'���)r!���ro���r���r���r����set_child_watcher���s���� z-_UnixDefaultEventLoopPolicy.set_child_watcher)r����r����r����r���Z _loop_factoryr���rx��ry��r_���rz��r����r���r���r#���r���rs�����s��� rs��)2rF���r����rc��r|���r����r<���r~���r����r��r(���rV��r,�����r���r���r���r���r���r���r ���r ���r���r����logr ����__all__r���ImportErrorr���ZBaseSelectorEventLoopr���Z ReadTransportrV���Z_FlowControlMixinZWriteTransportr]���ZBaseSubprocessTransportrb���r���r���rB��rH��r���r���r���r���ZBaseDefaultEventLoopPolicyrs��r���r���r���r���r���r����<module>���s`��� ���� ��NON5Ji}Y2