AlkantarClanX12

Your IP : 3.135.206.229


Current Path : /opt/alt/python311/lib64/python3.11/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/asyncio/__pycache__/unix_events.cpython-311.opt-1.pyc

�

c��f�����dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddl
mZddl
mZddl
mZddl
mZdd	l
mZdd
l
mZddl
mZddl
mZdd
l
mZddlmZdZe
jdkred���d�Zd�ZGd�dej��Z Gd�dej!��Z"Gd�dej#ej$��Z%Gd�dej&��Z'Gd�d��Z(Gd�de(��Z)Gd �d!e(��Z*Gd"�d#e*��Z+Gd$�d%e*��Z,Gd&�d'e(��Z-Gd(�d)e(��Z.Gd*�d+ej/��Z0e Z1e0Z2dS),z2Selector event loop for Unix with signal handling.�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��dS)zDummy signal handler.N�)�signum�frames  �:/opt/alt/python311/lib64/python3.11/asyncio/unix_events.py�_sighandler_noopr*s���D�c�P�	tj|��S#t$r|cYSwxYw�N)�os�waitstatus_to_exitcode�
ValueError)�statuss rr"r"/s>����(��0�0�0�������
�
�
�	���s��%�%c���eZdZdZd�fd�	Z�fd�Zd�Zd�Zd�Zd�Z	d	�Z
		dd
�Z		dd�Z	dd�Z
d
�Z	ddddddd�d�Z	dddddddd�d�Zd�Zd�Zd�Zd�Z�xZS)�_UnixSelectorEventLoopzdUnix event loop.

    Adds signal handling and UNIX Domain Socket support to SelectorEventLoop.
    Nc�X��t���|��i|_dSr )�super�__init__�_signal_handlers)�self�selector�	__class__s  �rr)z_UnixSelectorEventLoop.__init__?s)���
������"�"�"� "����rc�N��t�����tj��s.t	|j��D]}|�|���dS|jr;tjd|�d�t|���|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-s  �rr1z_UnixSelectorEventLoop.closeCs����
���
�
����� �"�"�
	.��D�1�2�2�
0�
0���*�*�3�/�/�/�/�
0�
0��$�
.��
�I�$�I�I�I�.�%)�	+�+�+�+�
�%�+�+�-�-�-�-�-�

.�
.rc�@�|D]}|s�|�|���dSr )�_handle_signal)r+�datars   r�_process_self_dataz)_UnixSelectorEventLoop._process_self_dataQs=���	(�	(�F��
������'�'�'�'�		(�	(rc�R�tj|��stj|��rtd���|�|��|���	t
j|j�	����n5#ttf$r!}tt|�����d}~wwxYwtj|||d��}||j|<	t
j|t"��t
j|d��dS#t$r�}|j|=|jsI	t
jd��n3#ttf$r}t'jd|��Yd}~nd}~wwxYw|jt*jkrtd|�d�����d}~wwxYw)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����set_wakeup_fd(-1) failed: %s�sig � cannot be caught)r�iscoroutine�iscoroutinefunction�	TypeError�
_check_signal�
_check_closed�signal�
set_wakeup_fd�_csock�filenor#�OSError�RuntimeError�strr�Handler*r�siginterruptr�info�errno�EINVAL)r+r:�callback�args�exc�handle�nexcs       r�add_signal_handlerz)_UnixSelectorEventLoop.add_signal_handlerXs���
�"�8�,�,�	9��.�x�8�8�	9��8�9�9�
9����3����������	)�

� ���!3�!3�!5�!5�6�6�6�6���G�$�	)�	)�	)��s�3�x�x�(�(�(�����	)������x��t�T�:�:��%+���c�"�	�
�M�#�/�0�0�0�
���U�+�+�+�+�+���	�	�	��%�c�*��(�
F�F��(��,�,�,�,��"�G�,�F�F�F��K� >��E�E�E�E�E�E�E�E�����F�����y�E�L�(�(�"�#@�#�#@�#@�#@�A�A�A������	���sZ�"+B�C�B;�;C�%/D�
F&� F!�0E�F!�E5�E0�+F!�0E5�5,F!�!F&c��|j�|��}|�dS|jr|�|��dS|�|��dS)z2Internal helper that is the actual signal handler.N)r*�get�
_cancelledr5�_add_callback_signalsafe)r+r:rXs   rr<z%_UnixSelectorEventLoop._handle_signal�sa���&�*�*�3�/�/���>��F���	2��&�&�s�+�+�+�+�+��)�)�&�1�1�1�1�1rc��|�|��	|j|=n#t$rYdSwxYw|tjkr
tj}ntj}	tj||��n;#t$r.}|jtj	krtd|�d�����d}~wwxYw|jsI	tjd��n3#ttf$r}tjd|��Yd}~nd}~wwxYwdS)zwRemove a handler for a signal.  UNIX only.

        Return True if a signal handler was removed, False if not.
        FrBrCNr@rAT)rGr*�KeyErrorrI�SIGINT�default_int_handler�SIG_DFLrMrSrTrNrJr#rrR)r+r:�handlerrWs    rr5z,_UnixSelectorEventLoop.remove_signal_handler�sK��
	
���3����	��%�c�*�*���	�	�	��5�5�	�����&�-����0�G�G��n�G�	��M�#�w�'�'�'�'���	�	�	��y�E�L�(�(�"�#@�#�#@�#@�#@�A�A�A������		�����$�	A�
A��$�R�(�(�(�(����(�
A�
A�
A���:�C�@�@�@�@�@�@�@�@�����
A�����ts<� �
.�.�A1�1
B)�;)B$�$B)�4C	�	C9�C4�4C9c��t|t��std|�����|tj��vrtd|�����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 zinvalid signal number N)�
isinstance�intrFrI�
valid_signalsr#)r+r:s  rrGz$_UnixSelectorEventLoop._check_signal�sa���#�s�#�#�	@��>�s�>�>�?�?�?��f�*�,�,�,�,��;�c�;�;�<�<�<�-�,rc�(�t|||||��Sr )�_UnixReadPipeTransport�r+�pipe�protocol�waiter�extras     r�_make_read_pipe_transportz0_UnixSelectorEventLoop._make_read_pipe_transport�s��%�d�D�(�F�E�J�J�Jrc�(�t|||||��Sr )�_UnixWritePipeTransportrks     r�_make_write_pipe_transportz1_UnixSelectorEventLoop._make_write_pipe_transport�s��&�t�T�8�V�U�K�K�Krc	��
K�tj��5}
|
���std���|���}t||||||||f||d�|	��}|
�|���|j|��	|�d{V��nN#ttf$r�t$r0|���|�
���d{V���wxYw	ddd��n#1swxYwY|S)NzRasyncio.get_child_watcher() is not activated, subprocess support is not installed.)rnro)r�get_child_watcher�	is_activerN�
create_future�_UnixSubprocessTransport�add_child_handler�get_pid�_child_watcher_callback�
SystemExit�KeyboardInterrupt�
BaseExceptionr1�_wait)
r+rmrV�shell�stdin�stdout�stderr�bufsizero�kwargs�watcherrn�transps
             r�_make_subprocess_transportz1_UnixSelectorEventLoop._make_subprocess_transport�s������
%�
'�
'�	�7��$�$�&�&�
K�
#�$J�K�K�K��'�'�)�)�F�-�d�H�d�E�.3�V�V�W�8�5;�5�8�8�17�8�8�F�

�%�%�f�n�n�&6�&6�&*�&B�F�
L�
L�
L�
������������ 1�2�
�
�
�� �
�
�
��������l�l�n�n�$�$�$�$�$�$�$��
�����#	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�2�
s+�A=C8�B�C8�AC(�(C8�8C<�?C<c�H�|�|j|j|��dSr )�call_soon_threadsafe�	call_soon�_process_exited)r+�pid�
returncoder�s    rr{z._UnixSelectorEventLoop._child_watcher_callback�s%���!�!�$�.�&�2H�*�U�U�U�U�Ur)�ssl�sock�server_hostname�ssl_handshake_timeout�ssl_shutdown_timeoutc���K�|r|�td���n3|�td���|�td���|�td���|��|�td���tj|��}tjtjtjd��}	|�d��|�||���d{V��n|#|����xYw|�td���|j	tjks|j
tjkrtd	|�����|�d��|�||||||�
���d{V��\}}	||	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�0ssl_shutdown_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�r�)r#r!�fspath�socket�AF_UNIX�SOCK_STREAM�setblocking�sock_connectr1�family�type�_create_connection_transport)
r+�protocol_factory�pathr�r�r�r�r��	transportrms
          r�create_unix_connectionz-_UnixSelectorEventLoop.create_unix_connection�s������	H��&� �E�G�G�G�'��*� �!N�O�O�O�$�0� �G�I�I�I�#�/� �F�H�H�H����� �I�K�K�K��9�T�?�?�D��=����1C�Q�G�G�D�
�� � ��'�'�'��'�'��d�3�3�3�3�3�3�3�3�3�3��
��
�
���������|� �!B�C�C�C���v�~�-�-��I��!3�3�3� �M�T�M�M�O�O�O����U�#�#�#�$(�$E�$E��"�C��"7�!5�%F�%7�%7�7�7�7�7�7�7��	�8��(�"�"s�1C�C%�dT)r��backlogr�r�r��
start_servingc	��K�t|t��rtd���|�|std���|�|std���|��Z|�td���t	j|��}t
jtjtj��}|ddvry	tj
t	j	|��j��rt	j|��n8#t$rYn,t$r }	tjd||	��Yd}	~	nd}	~	wwxYw	|�|��n�#t$rP}
|���|
jt&jkr!d|�d	�}tt&j|��d��d}
~
w|����xYw|�td
���|jtjks|jtjkrtd|�����|�d��t1j||g|||||��}|r.|���t7jd���d{V��|S)
Nz*ssl argument must be an SSLContext or Noner�r�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)rf�boolrFr#r!r�r�r�r��stat�S_ISSOCK�st_mode�remove�FileNotFoundErrorrMr�error�bindr1rS�
EADDRINUSEr�r�r�r�Server�_start_servingr�sleep)
r+r�r�r�r�r�r�r�r��errrW�msg�servers
             r�create_unix_serverz)_UnixSelectorEventLoop.create_unix_servers������c�4� � �	J��H�I�I�I� �,�S�,��C�E�E�
E� �+�C�+��B�D�D�
D����� �I�K�K�K��9�T�?�?�D��=����1C�D�D�D��A�w�k�)�)�6��}�R�W�T�]�]�%:�;�;�(��	�$������(�����D��6�6�6��L�"*�+/��6�6�6�6�6�6�6�6�����6����


��	�	�$�������
�
�
��
�
�����9�� 0�0�0�@�T�?�?�?�C�!�%�"2�C�8�8�d�B������
��
�
���������|� �C�E�E�E���v�~�-�-��I��!3�3�3� �M�T�M�M�O�O�O�	
��������#�D�4�&�2B�$'��2G�$8�:�:���	!��!�!�#�#�#��+�a�.�.� � � � � � � ��
s7�)?C)�)
D�5	D�>D�D�"D8�8
F'�AF
�
F'c
���K�	tjn"#t$rtjd���wxYw	|���}n2#ttjf$r}tjd���d}~wwxYw	tj|��j	}n"#t$rtjd���wxYw|r|n|}|sdS|���}	|�|	d|||||d��|	�d{V��S)Nzos.sendfile() is not availableznot a regular filer)
r!�sendfile�AttributeErrorr	�SendfileNotAvailableErrorrL�io�UnsupportedOperation�fstat�st_sizerMrw�_sock_sendfile_native_impl)
r+r��file�offset�countrLr��fsize�	blocksize�futs
          r�_sock_sendfile_nativez,_UnixSelectorEventLoop._sock_sendfile_native`sN����	2��K�K�K���	2�	2�	2��6�0�2�2�
2�	2����	M��[�[�]�]�F�F���� 7�8�	M�	M�	M��6�7K�L�L�L�����	M����	M��H�V�$�$�,�E�E���	M�	M�	M��6�7K�L�L�L�	M����"�-�E�E��	��	��1�� � �"�"���'�'��T�4��(.��y�!�	E�	E�	E��y�y�y�y�y�y�s+��0�A	�	A8�A3�3A8�<B�B5c	
�L�|���}	|�|�|��|���r|�|||��dS|r9||z
}|dkr.|�|||��|�|��dS	tj|	|||��}
|
dkr.|�|||��|�|��dS||
z
}||
z
}|�|�||��|�|	|j	||	||||||�
�
dS#ttf$r?|�|�||��|�|	|j	||	||||||�
�
YdSt$r�}|�N|j
tjkr9t|��t ur#t!dtj��}||_|}|dkrAt%jd��}
|�|||��|�|
��n2|�|||��|�|��Yd}~dSYd}~dSd}~wt*t,f$r�t.$r7}|�|||��|�|��Yd}~dSd}~wwxYw)Nrzsocket is not connectedzos.sendfile call failed)rL�
remove_writer�	cancelled�_sock_sendfile_update_filepos�
set_resultr!r��_sock_add_cancellation_callback�
add_writerr��BlockingIOError�InterruptedErrorrMrS�ENOTCONNr��ConnectionError�	__cause__r	r��
set_exceptionr|r}r~)r+r��
registered_fdr�rLr�r�r��
total_sent�fd�sentrW�new_excr�s              rr�z1_UnixSelectorEventLoop._sock_sendfile_native_implwsb��
�[�[�]�]���$�

���}�-�-�-��=�=�?�?�	��.�.�v�v�z�J�J�J��F��	��
�*�I��A�~�~��2�2�6�6�:�N�N�N����z�*�*�*���1	F��;�r�6�6�9�=�=�D�J�q�y�y��2�2�6�6�:�N�N�N����z�*�*�*�*�*��$����d�"�
� �(��8�8��d�C�C�C�����D�$C�S� "�D�&� &��y�*�F�F�F�F�F��[ �!1�2�	B�	B�	B��$��4�4�S�$�?�?�?��O�O�B�� ?����f�"�E�9�j�
B�
B�
B�
B�
B�
B��	'�	'�	'��)��I���/�/���I�I�_�4�4�
*�-�u�~�?�?��$'��!����Q���
!�:�-�/�/���2�2�6�6�:�N�N�N��!�!�#�&�&�&�&��2�2�6�6�:�N�N�N��!�!�#�&�&�&�&�&�&�&�&�&�'�&�&�&�&�&������-�.�	�	�	���	#�	#�	#��.�.�v�v�z�J�J�J����c�"�"�"�"�"�"�"�"�"�����	#���s,�D'�'AJ#�6	J#�?CI�J#�,,J�J#c�V�|dkr"tj||tj��dSdS�Nr)r!�lseek�SEEK_SET)r+rLr�r�s    rr�z4_UnixSelectorEventLoop._sock_sendfile_update_filepos�s.����>�>��H�V�V�R�[�1�1�1�1�1��>rc�@�����fd�}|�|��dS)Nc���|���r1����}|dkr��|��dSdSdS)Nr@)r�rLr�)r�r�r+r�s  ��r�cbzB_UnixSelectorEventLoop._sock_add_cancellation_callback.<locals>.cb�sR����}�}���
+��[�[�]�]����8�8��&�&�r�*�*�*�*�*�
+�
+��8r)�add_done_callback)r+r�r�r�s` ` rr�z6_UnixSelectorEventLoop._sock_add_cancellation_callback�s>����	+�	+�	+�	+�	+�	+�
	���b�!�!�!�!�!rr �NN)�__name__�
__module__�__qualname__�__doc__r)r1r>rZr<r5rGrprsr�r{r�r�r�r�r�r��
__classcell__�r-s@rr&r&9s����������
#�#�#�#�#�#�.�.�.�.�.�(�(�(�+�+�+�Z2�2�2����@
=�
=�
=�@D�(,�K�K�K�K�AE�)-�L�L�L�L�04�����<V�V�V�
*.�0#��4� �"&�!%�0#�0#�0#�0#�0#�f*.�G��s��"&�!%��G�G�G�G�G�R���.DF�DF�DF�L2�2�2�"�"�"�"�"�"�"rr&c���eZdZdZd�fd�	Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zejfd�Zdd�Zd�Zd�Z�xZS)rjiNc���t���|��||jd<||_||_|���|_||_d|_d|_	tj|j��j}tj|��sLtj|��s8tj|��s$d|_d|_d|_t#d���tj|jd��|j�|jj|��|j�|j|j|j��|�(|j�t.j|d��dSdS)NrlFz)Pipe transport is for pipes/sockets only.)r(r)�_extra�_loop�_piperL�_fileno�	_protocol�_closing�_pausedr!r�r�r��S_ISFIFOr��S_ISCHRr#�set_blockingr��connection_made�_add_reader�_read_readyr
�_set_result_unless_cancelled)r+�looprlrmrnro�moder-s       �rr)z_UnixReadPipeTransport.__init__�sb���
���������"���F����
���
��{�{�}�}���!�����
�����x���%�%�-���
�d�#�#�	J��
�d�#�#�	J���T�"�"�	J��D�J��D�L�!�D�N��H�I�I�I�
����e�,�,�,��
���T�^�;�T�B�B�B��
���T�-�!�\�4�+;�	=�	=�	=����J� � ��!E�!'��
/�
/�
/�
/�
/��rc�h�|���sdS|j�||��dSr )�
is_readingr�r�)r+r�rUs   rr�z"_UnixReadPipeTransport._add_reader�s7����� � �	��F��
���r�8�,�,�,�,�,rc�"�|jo|jSr )r�r��r+s rr�z!_UnixReadPipeTransport.is_reading�s���<��5��
�$5�5rc�`�|jjg}|j�|�d��n|jr|�d��|�d|j����t
|jdd��}|j�U|�Stj	||jtj��}|r|�d��nH|�d��n2|j�|�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+rRr,rs    r�__repr__z_UnixReadPipeTransport.__repr__�s ����'�(���:���K�K��!�!�!�!�
�]�	#��K�K�	�"�"�"����(�$�,�(�(�)�)�)��4�:�{�D�9�9���:�!�h�&:�%�:��$�,�	�(<�>�>�G��
$����I�&�&�&�&����F�#�#�#�#�
�Z�
#��K�K�������K�K��!�!�!��}�}�S�X�X�d�^�^�,�,�,rc�4�	tj|j|j��}|r|j�|��dS|j���rtj	d|��d|_
|j�|j��|j�|jj
��|j�|jd��dS#tt f$rYdSt"$r!}|�|d��Yd}~dSd}~wwxYw)N�%r was closed by peerTz"Fatal read error on pipe transport)r!�readr��max_sizer��
data_receivedr��	get_debugrrRr��_remove_readerr��eof_received�_call_connection_lostr�r�rM�_fatal_error)r+r=rWs   rr�z"_UnixReadPipeTransport._read_ready	s5��	G��7�4�<���7�7�D��
G���,�,�T�2�2�2�2�2��:�'�'�)�)�?��K� 7��>�>�>� $��
��
�)�)�$�,�7�7�7��
�$�$�T�^�%@�A�A�A��
�$�$�T�%?��F�F�F�F�F�� �!1�2�	�	�	��D�D��	I�	I�	I����c�#G�H�H�H�H�H�H�H�H�H�����	I���s�C�D�-	D�6D�Dc���|���sdSd|_|j�|j��|j���rt
jd|��dSdS)NTz%r pauses reading)r�r�r�rr�rr�debugrs r�
pause_readingz$_UnixReadPipeTransport.pause_readingsq����� � �	��F�����
�!�!�$�,�/�/�/��:���!�!�	4��L�,�d�3�3�3�3�3�	4�	4rc���|js|jsdSd|_|j�|j|j��|j���rtjd|��dSdS)NFz%r resumes reading)	r�r�r�r�r�r�rrrrs r�resume_readingz%_UnixReadPipeTransport.resume_reading#sw���=�	���	��F�����
���t�|�T�-=�>�>�>��:���!�!�	5��L�-�t�4�4�4�4�4�	5�	5rc��||_dSr �r��r+rms  r�set_protocolz#_UnixReadPipeTransport.set_protocol+�
��!����rc��|jSr r$rs r�get_protocolz#_UnixReadPipeTransport.get_protocol.�
���~�rc��|jSr �r�rs r�
is_closingz!_UnixReadPipeTransport.is_closing1�
���}�rc�B�|js|�d��dSdSr )r��_closers rr1z_UnixReadPipeTransport.close4s.���}�	��K�K�������	�	rc�v�|j�1|d|��t|���|j���dSdS�Nzunclosed transport r/�r�r8r1�r+�_warns  r�__del__z_UnixReadPipeTransport.__del__8�L���:�!��E�0��0�0�/�$�O�O�O�O��J��������"�!r�Fatal error on pipe transportc�0�t|t��rG|jtjkr2|j���rt
jd||d���n$|j�||||j	d���|�
|��dS�Nz%r: %sT��exc_info)�message�	exceptionr�rm)rfrMrS�EIOr�rrr�call_exception_handlerr�r0�r+rWr=s   rrz#_UnixReadPipeTransport._fatal_error=s����s�G�$�$�		���e�i�)?�)?��z�#�#�%�%�
E���X�t�W�t�D�D�D�D���J�-�-�"� �!� �N�	/�/�
�
�
�	
���C�����rc��d|_|j�|j��|j�|j|��dS�NT)r�r�rr�r�r�r+rWs  rr0z_UnixReadPipeTransport._closeKsB����
��
�!�!�$�,�/�/�/��
���T�7��=�=�=�=�=rc��	|j�|��|j���d|_d|_d|_dS#|j���d|_d|_d|_wxYwr �r��connection_lostr�r1r�rDs  rrz,_UnixReadPipeTransport._call_connection_lostP���	��N�*�*�3�/�/�/��J�������D�J�!�D�N��D�J�J�J��
�J�������D�J�!�D�N��D�J������A�0A<r��r8)r�r�r�rr)r�r�rr�r r"r&r)r-r1r6r7r6rr0rr�r�s@rrjrj�s(��������H�/�/�/�/�/�/�<-�-�-�
6�6�6�-�-�-�*G�G�G�$4�4�4�5�5�5�"�"�"����������%�M�����
����>�>�>�
������rrjc���eZdZd�fd�	Zd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zejfd�Zd�Zdd�Zdd�Zd�Z�xZS)rrNc�p��t���||��||jd<||_|���|_||_t��|_d|_	d|_
tj|j��j
}tj|��}tj|��}tj|��}	|s(|s&|	s$d|_d|_d|_t%d���tj|jd��|j�|jj|��|	s!|rOt.j�d��s0|j�|jj|j|j��|�(|j�t8j|d��dSdS)NrlrFz?Pipe transport is only for pipes, sockets and character devices�aix)r(r)r�r�rLr�r��	bytearray�_buffer�
_conn_lostr�r!r�r�r�r�r�r�r#r�r�r�r�r2�platform�
startswithr�r�r
r�)r+r�rlrmrnror��is_char�is_fifo�	is_socketr-s          �rr)z _UnixWritePipeTransport.__init__]s����
�������%�%�%�"���F����
��{�{�}�}���!��� �{�{��������
��x���%�%�-���,�t�$�$���-��%�%���M�$�'�'�	��	E�7�	E�i�	E��D�J��D�L�!�D�N��D�E�E�
E�	����e�,�,�,��
���T�^�;�T�B�B�B�
�	A��	A���)@�)@��)G�)G�	A��J� � ���!7�!%��t�/?�
A�
A�
A����J� � ��!E�!'��
/�
/�
/�
/�
/��rc��|jjg}|j�|�d��n|jr|�d��|�d|j����t
|jdd��}|j��|�tj	||jtj��}|r|�d��n|�d��|���}|�d|����n2|j�|�d��n|�d��d	�
d
�|����S)Nrrrrrrzbufsize=r	r
r)r-r�r�rr�r�r
r�rrr�EVENT_WRITE�get_write_buffer_sizerr)r+rRr,rr�s     rrz _UnixWritePipeTransport.__repr__�sL����'�(���:���K�K��!�!�!�!�
�]�	#��K�K�	�"�"�"����(�$�,�(�(�)�)�)��4�:�{�D�9�9���:�!�h�&:�%�:��$�,�	�(=�?�?�G��
$����I�&�&�&�&����F�#�#�#��0�0�2�2�G��K�K�,�7�,�,�-�-�-�-�
�Z�
#��K�K�������K�K��!�!�!��}�}�S�X�X�d�^�^�,�,�,rc�*�t|j��Sr )�lenrOrs rrXz-_UnixWritePipeTransport.get_write_buffer_size�s���4�<� � � rc���|j���rtjd|��|jr#|�t
����dS|���dS)Nr)r�rrrRrOr0�BrokenPipeErrorrs rr�z#_UnixWritePipeTransport._read_ready�sd���:���!�!�	7��K�/��6�6�6��<�	��K�K��)�)�*�*�*�*�*��K�K�M�M�M�M�Mrc���t|t��rt|��}|sdS|js|jr;|jt
jkrtjd��|xjdz
c_dS|j	s�	tj|j|��}nc#ttf$rd}YnNtt f$r�t"$r1}|xjdz
c_|�|d��Yd}~dSd}~wwxYw|t'|��krdS|dkrt|��|d�}|j�|j|j��|xj	|z
c_	|���dS)Nz=pipe closed by peer or os.write(pipe, data) raised exception.rr�#Fatal write error on pipe transport)rfrN�
memoryviewrPr�r�!LOG_THRESHOLD_FOR_CONNLOST_WRITESr�warningrOr!�writer�r�r�r|r}r~rrZr��_add_writer�_write_ready�_maybe_pause_protocol)r+r=�nrWs    rrbz_UnixWritePipeTransport.write�s����d�I�&�&�	$��d�#�#�D��	��F��?�	�d�m�	���)�"M�M�M��� H�I�I�I��O�O�q� �O�O��F��|�	D�	
��H�T�\�4�0�0����#�%5�6�
�
�
������ 1�2�
�
�
�� �
�
�
����1�$����!�!�#�'L�M�M�M�����������
�����C��I�I�~�~����Q���!�$�'�'����+���J�"�"�4�<��1B�C�C�C���������"�"�$�$�$�$�$s�:B�C5�*C5�&C0�0C5c���	tj|j|j��}|t	|j��kr�|j���|j�|j��|���|j	r4|j�
|j��|�d��dS|dkr|jd|�=dSdS#ttf$rYdSttf$r�t $ri}|j���|xjdz
c_|j�|j��|�|d��Yd}~dSd}~wwxYw)Nrrr^)r!rbr�rOrZr9r��_remove_writer�_maybe_resume_protocolr�rrr�r�r|r}r~rPr)r+rfrWs   rrdz$_UnixWritePipeTransport._write_ready�s���	%�����t�|�4�4�A��C���%�%�%�%���"�"�$�$�$��
�)�)�$�,�7�7�7��+�+�-�-�-��=�5��J�-�-�d�l�;�;�;��.�.�t�4�4�4����Q����L��!��$�$�$����) �!1�2�	�	�	��D�D��-�.�	�	�	���	J�	J�	J��L��� � � ��O�O�q� �O�O�
�J�%�%�d�l�3�3�3����c�#H�I�I�I�I�I�I�I�I�I�����
	J���s�C�E-�*E-�AE(�(E-c��dSrCrrs r�
can_write_eofz%_UnixWritePipeTransport.can_write_eof�����trc��|jrdSd|_|jsA|j�|j��|j�|jd��dSdSrC)r�rOr�rr�r�rrs r�	write_eofz!_UnixWritePipeTransport.write_eof�sh���=�	��F���
��|�	C��J�%�%�d�l�3�3�3��J� � ��!;�T�B�B�B�B�B�	C�	Crc��||_dSr r$r%s  rr&z$_UnixWritePipeTransport.set_protocol�r'rc��|jSr r$rs rr)z$_UnixWritePipeTransport.get_protocol�r*rc��|jSr r,rs rr-z"_UnixWritePipeTransport.is_closing�r.rc�R�|j�|js|���dSdSdSr )r�r�rnrs rr1z_UnixWritePipeTransport.close�s5���:�!�$�-�!��N�N������"�!�!�!rc�v�|j�1|d|��t|���|j���dSdSr2r3r4s  rr6z_UnixWritePipeTransport.__del__�r7rc�0�|�d��dSr )r0rs r�abortz_UnixWritePipeTransport.aborts�����D�����rr8c��t|t��r2|j���rt	jd||d���n$|j�||||jd���|�|��dSr:)	rfrMr�rrrr@r�r0rAs   rrz$_UnixWritePipeTransport._fatal_errors����c�7�#�#�		��z�#�#�%�%�
E���X�t�W�t�D�D�D�D���J�-�-�"� �!� �N�	/�/�
�
�
�	
���C�����rc��d|_|jr|j�|j��|j���|j�|j��|j�|j|��dSrC)	r�rOr�rhr�r9rr�rrDs  rr0z_UnixWritePipeTransport._closesx����
��<�	4��J�%�%�d�l�3�3�3���������
�!�!�$�,�/�/�/��
���T�7��=�=�=�=�=rc��	|j�|��|j���d|_d|_d|_dS#|j���d|_d|_d|_wxYwr rFrDs  rrz-_UnixWritePipeTransport._call_connection_lostrHrIr�rJr )r�r�r�r)rrXr�rbrdrkrnr&r)r-r1r6r7r6rurr0rr�r�s@rrrrrZsH�������#/�#/�#/�#/�#/�#/�J-�-�-�0!�!�!����!%�!%�!%�F%�%�%�8���C�C�C�"�"�"����������
%�M�����
�������>�>�>�>�������rrrc��eZdZd�ZdS)rxc
��d}|tjkr5tj�d��rtj��\}}	tj|f||||d|d�|��|_|�D|�	��t|���d|���|j_d}|�*|�	��|�	��dSdS#|�)|�	��|�	��wwxYw)NrMF)r�r�r�r��universal_newlinesr��wb)�	buffering)
�
subprocess�PIPEr2rQrRr��
socketpair�Popen�_procr1r	�detachr�)	r+rVr�r�r�r�r�r��stdin_ws	         r�_startz_UnixSubprocessTransport._start)s�����J�O�#�#���(?�(?��(F�(F�#�
$�.�0�0�N�E�7�	 �#�)��E�!��v�f�#(�'�E�E�=C�E�E�D�J��"����
�
�
�#'����(8�(8�$�'�#R�#R�#R��
� ����"����
�
�
��
�
������#�"��w�"����
�
�
��
�
�����#���s
�	A$C�-DN)r�r�r�r�rrrrxrx's#������ � � � � rrxc�<�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	S)
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.
    c��t���)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.
        ��NotImplementedError�r+r�rUrVs    rryz&AbstractChildWatcher.add_child_handlerVs��"�#�#�#rc��t���)z�Removes the handler for process 'pid'.

        The function returns True if the handler was successfully removed,
        False if there was nothing to remove.r��r+r�s  r�remove_child_handlerz)AbstractChildWatcher.remove_child_handleras��"�#�#�#rc��t���)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.
        r��r+r�s  r�attach_loopz AbstractChildWatcher.attach_loopis��"�#�#�#rc��t���)zlClose the watcher.

        This must be called to make sure that any underlying resource is freed.
        r�rs rr1zAbstractChildWatcher.closess��
"�#�#�#rc��t���)z�Return ``True`` if the watcher is active and is used by the event loop.

        Return True if the watcher is installed and ready to handle process exit
        notifications.

        r�rs rrvzAbstractChildWatcher.is_activezs��"�#�#�#rc��t���)zdEnter the watcher's context and allow starting new processes

        This function must return selfr�rs r�	__enter__zAbstractChildWatcher.__enter__�s��"�#�#�#rc��t���)zExit the watcher's contextr��r+�a�b�cs    r�__exit__zAbstractChildWatcher.__exit__�s��!�#�#�#rN)r�r�r�r�ryr�r�r1rvr�r�rrrrr?s���������,	$�	$�	$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$rrc�H�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�ZdS)ra6Child watcher implementation using Linux's pid file descriptors.

    This child watcher polls process file descriptors (pidfds) to await child
    process termination. In some respects, PidfdChildWatcher is a "Goldilocks"
    child watcher implementation. It doesn't require signals or threads, doesn't
    interfere with any processes launched outside the event loop, and scales
    linearly with the number of subprocesses launched by the event loop. The
    main disadvantage is that pidfds are specific to Linux, and only work on
    recent (5.3+) kernels.
    c�"�d|_i|_dSr �r��
_callbacksrs rr)zPidfdChildWatcher.__init__������
�����rc��|Sr rrs rr�zPidfdChildWatcher.__enter__�����rc��dSr r)r+�exc_type�	exc_value�
exc_tracebacks    rr�zPidfdChildWatcher.__exit__�����rc�F�|jduo|j���Sr �r��
is_runningrs rrvzPidfdChildWatcher.is_active��"���z��%�A�$�*�*?�*?�*A�*A�Arc�0�|�d��dSr �r�rs rr1zPidfdChildWatcher.close������������rc�6�|j�#|�!|jrtjdt��|j���D]4\}}}|j�|��tj|���5|j�	��||_dS�NzCA loop is being detached from a child watcher with pending handlers)
r�r�r6r7�RuntimeWarning�valuesrr!r1r9)r+r��pidfd�_s    rr�zPidfdChildWatcher.attach_loop�s����:�!�d�l�t��l��M�=��
 �
 �
 � �?�1�1�3�3�	�	�K�E�1�a��J�%�%�e�,�,�,��H�U�O�O�O�O����������
�
�
rc���|j�|��}|�|d||f|j|<dStj|��}|j�||j|��|||f|j|<dSr�)r�r\r!�
pidfd_openr�r��_do_wait)r+r�rUrV�existingr�s      rryz#PidfdChildWatcher.add_child_handler�s~���?�&�&�s�+�+����#+�A�;��$�#>�D�O�C� � � ��M�#�&�&�E��J�"�"�5�$�-��=�=�=�#(�(�D�#8�D�O�C� � � rc�R�|j�|��\}}}|j�|��	t	j|d��\}}t
|��}n'#t$rd}tj	d|��YnwxYwt	j
|��|||g|�R�dS)Nr�zJchild process pid %d exit status already read:  will report returncode 255)r��popr�rr!�waitpidr"�ChildProcessErrorrrar1)r+r�r�rUrVr�r$r�s        rr�zPidfdChildWatcher._do_wait�s��� $�� 3� 3�C� 8� 8���x���
�!�!�%�(�(�(�	8��
�3��*�*�I�A�v�0��7�7�J�J��!�	�	�	��J��N�.��
�
�
�
�
�		����	���������j�(�4�(�(�(�(�(�(s�A"�"!B�Bc���	|j�|��\}}}n#t$rYdSwxYw|j�|��tj|��dS)NFT)r�r�r`r�rr!r1)r+r�r�r�s    rr�z&PidfdChildWatcher.remove_child_handler�sn��	��/�-�-�c�2�2�K�E�1�a�a���	�	�	��5�5�	�����
�!�!�%�(�(�(�
�������ts�!�
/�/N)
r�r�r�r�r)r�r�rvr1r�ryr�r�rrrrr�s�������	�	�������
�
�
�B�B�B����
�
�
�9�9�9�)�)�)�&����rrc�8�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�BaseChildWatcherc�"�d|_i|_dSr r�rs rr)zBaseChildWatcher.__init__�r�rc�0�|�d��dSr r�rs rr1zBaseChildWatcher.close�r�rc�F�|jduo|j���Sr r�rs rrvzBaseChildWatcher.is_active�r�rc��t���r r�)r+�expected_pids  r�_do_waitpidzBaseChildWatcher._do_waitpid����!�#�#�#rc��t���r r�rs r�_do_waitpid_allz BaseChildWatcher._do_waitpid_all�r�rc�8�|j�#|�!|jrtjdt��|j�$|j�tj��||_|�;|�tj|j	��|�
��dSdSr�)r�r�r6r7r�r5rI�SIGCHLDrZ�	_sig_chldr�r�s  rr�zBaseChildWatcher.attach_loop�s����:�!�d�l�t��l��M�=��
 �
 �
 �
�:�!��J�,�,�V�^�<�<�<���
����#�#�F�N�D�N�C�C�C�
� � �"�"�"�"�"��rc��	|���dS#ttf$r�t$r(}|j�d|d���Yd}~dSd}~wwxYw)N�$Unknown exception in SIGCHLD handler)r=r>)r�r|r}r~r�r@rDs  rr�zBaseChildWatcher._sig_chlds���	�� � �"�"�"�"�"���-�.�	�	�	���	�	�	�
�J�-�-�A� �/�/�
�
�
�
�
�
�
�
�
�����		���s��A�A�AN)
r�r�r�r)r1rvr�r�r�r�rrrr�r��s�������������B�B�B�$�$�$�$�$�$�#�#�#�(����rr�c�F��eZdZdZ�fd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
�xZS)	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)
    c�z��|j���t�����dSr )r�r9r(r1�r+r-s �rr1zSafeChildWatcher.closes,����������
���
�
�����rc��|Sr rrs rr�zSafeChildWatcher.__enter__ r�rc��dSr rr�s    rr�zSafeChildWatcher.__exit__#r�rc�H�||f|j|<|�|��dSr )r�r�r�s    rryz"SafeChildWatcher.add_child_handler&s/�� (�$�/�����	
��������rc�:�	|j|=dS#t$rYdSwxYw�NTF�r�r`r�s  rr�z%SafeChildWatcher.remove_child_handler,�8��	����$��4���	�	�	��5�5�	������
�c�^�t|j��D]}|�|���dSr �r4r�r�r�s  rr�z SafeChildWatcher._do_waitpid_all3s<�����(�(�	"�	"�C����S�!�!�!�!�	"�	"rc��	tj|tj��\}}|dkrdSt|��}|j���rt
jd||��n)#t$r|}d}t
j	d|��YnwxYw	|j
�|��\}}|||g|�R�dS#t$r7|j���rt
j	d|d���YdSYdSwxYw)Nr�$process %s exited with returncode %sr��8Unknown child process pid %d, will report returncode 255�'Child watcher got an unexpected pid: %rTr;)
r!r��WNOHANGr"r�rrrr�rar�r�r`)r+r�r�r$r�rUrVs       rr�zSafeChildWatcher._do_waitpid8so��	7��*�\�2�:�>�>�K�C���a�x�x���/��7�7�J��z�#�#�%�%�
7���C�)�:�7�7�7���!�	�	�	��C��J��N�J��
�
�
�
�
�	����$		-�!�_�0�0��5�5�N�H�d�
�H�S�*�,�t�,�,�,�,�,�,���	3�	3�	3��z�#�#�%�%�
3���H�"�T�3�3�3�3�3�3�3�
3�
3�
3�	3���s#�"A+�+#B�B�B>�>:C?�>C?)r�r�r�r�r1r�r�ryr�r�r�r�r�s@rrrs������������������
�
�
�������"�"�"�
 -� -� -� -� -� -� -rrc�J��eZdZdZ�fd�Z�fd�Zd�Zd�Zd�Zd�Z	d�Z
�xZS)	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).
    c���t�����tj��|_i|_d|_dSr�)r(r)�	threading�Lock�_lock�_zombies�_forksr�s �rr)zFastChildWatcher.__init__es:���
���������^�%�%��
���
�����rc���|j���|j���t�����dSr )r�r9r�r(r1r�s �rr1zFastChildWatcher.closeks@�����������
������
���
�
�����rc�h�|j5|xjdz
c_|cddd��S#1swxYwYdS)Nr)r�r�rs rr�zFastChildWatcher.__enter__ps���
�Z�	�	��K�K�1��K�K��	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�'�+�+c� �|j5|xjdzc_|js|js	ddd��dSt|j��}|j���ddd��n#1swxYwYtjd|��dS)Nrz5Caught subprocesses termination from unknown pids: %s)r�r�r�rOr9rra)r+r�r�r��collateral_victimss     rr�zFastChildWatcher.__exit__vs���
�Z�	"�	"��K�K�1��K�K��{�
�$�-�
��		"�	"�	"�	"�	"�	"�	"�	"�"%�T�]�!3�!3���M���!�!�!�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	��C��	 �	 �	 �	 �	 s� A.�-A.�.A2�5A2c���|j5	|j�|��}n(#t$r||f|j|<Yddd��dSwxYw	ddd��n#1swxYwY|||g|�R�dSr )r�r�r�r`r�)r+r�rUrVr�s     rryz"FastChildWatcher.add_child_handler�s����Z�	�	�
�!�]�.�.�s�3�3�
�
���
�
�
�'/��~����$��
	�	�	�	�	�	�	�	�
�����	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	���j�(�4�(�(�(�(�(�(s0�A�%�A�A
�A�	A
�
A�A�!Ac�:�	|j|=dS#t$rYdSwxYwr�r�r�s  rr�z%FastChildWatcher.remove_child_handler�r�r�c�~�		tjdtj��\}}|dkrdSt|��}n#t$rYdSwxYw|j5	|j�|��\}}|j�	��rtjd||��n_#t$rR|j
rF||j|<|j�	��rtjd||��Yddd����d}YnwxYwddd��n#1swxYwY|�tjd||��n
|||g|�R���=)NTr@rr�z,unknown process %s exited with returncode %sz8Caught subprocess termination from unknown pid: %d -> %d)r!r�r�r"r�r�r�r�r�rrrr`r�r�ra)r+r�r$r�rUrVs      rr�z FastChildWatcher._do_waitpid_all�s���%	1�

<� �j��R�Z�8�8���V�
�!�8�8��F�3�F�;�;�
�
��%�
�
�
����
������
6�
6�6�%)�_�%8�%8��%=�%=�N�H�d��z�+�+�-�-�6���%K�%(�*�6�6�6��� �
$�
$�
$��{�!�-7��
�c�*��:�/�/�1�1�:�"�L�*>�),�j�:�:�:�!�
6�
6�
6�
6�
6�
6�
6� $�H�H�H�
$����
6�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6����
6�
6�
6�
6�&����� #�Z�1�1�1�1����j�0�4�0�0�0�0�K%	1sR�"=�
A�
A�D�B$�40D�$A
D�.D�;D�=D�?D�D�D�D)r�r�r�r�r)r1r�r�ryr�r�r�r�s@rrr[s��������������������
��� � � �)�)�)����(1�(1�(1�(1�(1�(1�(1rrc�T�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
S)ra~A watcher that doesn't require running loop in the main thread.

    This implementation registers a SIGCHLD signal handler on
    instantiation (which may conflict with other code that
    install own handler for this signal).

    The solution is safe but it has a significant overhead when
    handling a big number of processes (*O(n)* each time a
    SIGCHLD is received).
    c�"�i|_d|_dSr )r��_saved_sighandlerrs rr)zMultiLoopChildWatcher.__init__�s�����!%����rc��|jduSr )r�rs rrvzMultiLoopChildWatcher.is_active�s���%�T�1�1rc��|j���|j�dStjtj��}||jkrtjd��n$tjtj|j��d|_dS)Nz+SIGCHLD handler was changed by outside code)	r�r9r�rI�	getsignalr�r�rra)r+rds  rr1zMultiLoopChildWatcher.close�s|����������!�)��F��"�6�>�2�2���d�n�$�$��N�H�I�I�I�I��M�&�.�$�*@�A�A�A�!%����rc��|Sr rrs rr�zMultiLoopChildWatcher.__enter__�r�rc��dSr r�r+r��exc_val�exc_tbs    rr�zMultiLoopChildWatcher.__exit__�r�rc�p�tj��}|||f|j|<|�|��dSr )r�get_running_loopr�r�)r+r�rUrVr�s     rryz'MultiLoopChildWatcher.add_child_handler�s?���&�(�(�� $�h��5�����	
��������rc�:�	|j|=dS#t$rYdSwxYwr�r�r�s  rr�z*MultiLoopChildWatcher.remove_child_handler�r�r�c��|j�dStjtj|j��|_|j�%t	jd��tj|_tjtjd��dS)NzaPrevious SIGCHLD handler was set by non-Python code, restore to default handler on watcher close.F)r�rIr�r�rrarcrQr�s  rr�z!MultiLoopChildWatcher.attach_loop�sw��
�!�-��F�!'��v�~�t�~�!N�!N����!�)��N�J�
K�
K�
K�%+�^�D�"�	��F�N�E�2�2�2�2�2rc�^�t|j��D]}|�|���dSr r�r�s  rr�z%MultiLoopChildWatcher._do_waitpid_alls<�����(�(�	"�	"�C����S�!�!�!�!�	"�	"rc�4�	tj|tj��\}}|dkrdSt|��}d}n+#t$r|}d}tjd|��d}YnwxYw	|j�|��\}}}|�	��rtjd||��dS|r*|�
��rtjd||��|j|||g|�R�dS#t$rtjd|d�	��YdSwxYw)
NrTr�r�F�%Loop %r that handles pid %r is closedr�r�r;)r!r�r�r"r�rrar�r��	is_closedrrr�r`)	r+r�r�r$r��	debug_logr�rUrVs	         rr�z!MultiLoopChildWatcher._do_waitpids���	��*�\�2�:�>�>�K�C���a�x�x���/��7�7�J��I�I��!�	�	�	��C��J��N�J��
�
�
��I�I�I�	���� 	L�#'�?�#6�#6�s�#;�#;� �D�(�D��~�~���
L���F��c�R�R�R�R�R��;����!1�!1�;��L�!G�!-�z�;�;�;�)��)�(�C��K�d�K�K�K�K�K�K���	/�	/�	/�
�N�D���
/�
/�
/�
/�
/�
/�
/�	/���s!�">�%A&�%A&�*C2�2!D�Dc��	|���dS#ttf$r�t$rt	jdd���YdSwxYw)Nr�Tr;)r�r|r}r~rra)r+rrs   rr�zMultiLoopChildWatcher._sig_chld8sy��	R�� � �"�"�"�"�"���-�.�	�	�	���	R�	R�	R��N�A�D�Q�Q�Q�Q�Q�Q�Q�	R���s��1A
�A
N)r�r�r�r�r)rvr1r�r�ryr�r�r�r�r�rrrrr�s�������	�	�$&�&�&�2�2�2�
&�
&�
&����
�
�
�������3�3�3�""�"�"�#L�#L�#L�JR�R�R�R�Rrrc�\�eZdZdZd�Zd�Zd�Zd�Zd�Ze	j
fd�Zd�Zd	�Z
d
�Zd�ZdS)
raAThreaded child watcher implementation.

    The watcher uses a thread per process
    for waiting for the process finish.

    It doesn't require subscription on POSIX signal
    but a thread creation is not free.

    The watcher has O(1) complexity, its performance doesn't depend
    on amount of spawn processes.
    c�F�tjd��|_i|_dSr�)�	itertoolsr��_pid_counter�_threadsrs rr)zThreadedChildWatcher.__init__Ns��%�O�A�.�.�����
�
�
rc��dSrCrrs rrvzThreadedChildWatcher.is_activeRrlrc��dSr rrs rr1zThreadedChildWatcher.closeUr�rc��|Sr rrs rr�zThreadedChildWatcher.__enter__Xr�rc��dSr rr�s    rr�zThreadedChildWatcher.__exit__[r�rc��d�t|j�����D��}|r||j�d�t|���dSdS)Nc�:�g|]}|����|��Sr)�is_alive)�.0�threads  r�
<listcomp>z0ThreadedChildWatcher.__del__.<locals>.<listcomp>_s6��)�)�)�f��o�o�'�'�)�6�)�)�)rz0 has registered but not finished child processesr/)r4rr�r-r8)r+r5�threadss   rr6zThreadedChildWatcher.__del__^s}��)�)��T�]�-A�-A�-C�-C�(D�(D�)�)�)���	��E�T�^�U�U�U�!��
�
�
�
�
�
�	�	rc���tj��}tj|jdt|j����||||fd���}||j|<|���dS)Nzasyncio-waitpid-T)�target�namerV�daemon)	rr�r��Threadr��nextrr�start)r+r�rUrVr�rs      rryz&ThreadedChildWatcher.add_child_handlerfsp���&�(�(���!��)9�'S�$�t�?P�:Q�:Q�'S�'S�(,�c�8�T�'B�)-�/�/�/��$��
�c���������rc��dSrCrr�s  rr�z)ThreadedChildWatcher.remove_child_handleros	���trc��dSr rr�s  rr�z ThreadedChildWatcher.attach_loopur�rc��	tj|d��\}}t|��}|���rt	jd||��n)#t$r|}d}t	jd|��YnwxYw|���rt	jd||��n|j	|||g|�R�|j
�|��dS)Nrr�r�r�r�)r!r�r"rrrr�rarr�rr�)r+r�r�rUrVr�r$r�s        rr�z ThreadedChildWatcher._do_waitpidxs��	7��*�\�1�5�5�K�C��0��7�7�J��~�~���
7���C�)�:�7�7�7���!�	�	�	��C��J��N�J��
�
�
�
�
�	�����>�>���	H��N�B�D�#�N�N�N�N�%�D�%�h��Z�G�$�G�G�G�G��
���,�'�'�'�'�'s�A�#A:�9A:N)r�r�r�r�r)rvr1r�r�r6r7r6ryr�r�r�rrrrrAs�������
�
�������
�
�
����
�
�
�%�M�����������
�
�
�(�(�(�(�(rrc�B��eZdZdZeZ�fd�Zd�Z�fd�Zd�Z	d�Z
�xZS)�_UnixDefaultEventLoopPolicyz:UNIX event loop policy with a watcher for child processes.c�V��t�����d|_dSr )r(r)�_watcherr�s �rr)z$_UnixDefaultEventLoopPolicy.__init__�s$���
����������
�
�
rc��tj5|j�t��|_ddd��dS#1swxYwYdSr )rr�r rrs r�
_init_watcherz)_UnixDefaultEventLoopPolicy._init_watcher�s���
�\�	7�	7��}�$� 4� 6� 6��
�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7����	7�	7�	7�	7�	7�	7s�5�9�9c����t���|��|j�Btj��tj��ur|j�|��dSdSdS)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 r��current_thread�main_threadr�)r+r�r-s  �rr$z*_UnixDefaultEventLoopPolicy.set_event_loop�sl���	�����t�$�$�$��M�%��(�*�*�i�.C�.E�.E�E�E��M�%�%�d�+�+�+�+�+�
&�%�E�Erc�F�|j�|���|jS)z~Get the watcher for child processes.

        If not yet set, a ThreadedChildWatcher object is automatically created.
        )r r"rs rruz-_UnixDefaultEventLoopPolicy.get_child_watcher�s&��
�=� ���� � � ��}�rc�T�|j�|j���||_dS)z$Set the watcher for child processes.N)r r1)r+r�s  r�set_child_watcherz-_UnixDefaultEventLoopPolicy.set_child_watcher�s+��
�=�$��M���!�!�!���
�
�
r)r�r�r�r�r&�
_loop_factoryr)r"r$rur)r�r�s@rrr�s��������D�D�*�M������7�7�7�
,�,�,�,�,���� � � � � � � rr)3r�rSr�rr!rrIr�r�r~r2r�r6�rrrrrr	r
rrr
�logr�__all__rQ�ImportErrorrr"�BaseSelectorEventLoopr&�
ReadTransportrj�_FlowControlMixin�WriteTransportrr�BaseSubprocessTransportrxrrr�rrrr�BaseDefaultEventLoopPolicyrrrrrr�<module>r5s��8�8�����	�	�	�	�����	�	�	�	�����
�
�
�
�
�
�
�
���������
�
�
�
������������������������������������������������������������������������������<�7���
�+�C�
D�
D�D�	�	�	�
���N"�N"�N"�N"�N"�_�B�N"�N"�N"�bM�M�M�M�M�Z�5�M�M�M�`J�J�J�J�J�j�:�(�7�J�J�J�Z � � � � ��F� � � �0L$�L$�L$�L$�L$�L$�L$�L$�^K�K�K�K�K�,�K�K�K�\2�2�2�2�2�+�2�2�2�jG-�G-�G-�G-�G-�'�G-�G-�G-�Tf1�f1�f1�f1�f1�'�f1�f1�f1�RzR�zR�zR�zR�zR�0�zR�zR�zR�zO(�O(�O(�O(�O(�/�O(�O(�O(�d- �- �- �- �- �&�"C�- �- �- �`+��4���r