
    F\h                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  Sr\
R6                  S:X  a  \" S5      eS rS r " S S\R>                  5      r  " S S\RB                  5      r" " S S\RF                  \RH                  5      r% " S S\RL                  5      r' " S S5      r( " S S\(5      r) " S  S!\(5      r* " S" S#\*5      r+ " S$ S%\*5      r, " S& S'\(5      r- " S( S)\(5      r.S* r/ " S+ S,\R`                  5      r1\ r2\1r3\2r4g)-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	EventLoopwin32z+Signals are not really supported on Windowsc                     g)zDummy signal handler.N )signumframes     */usr/lib/python3.13/asyncio/unix_events.py_sighandler_noopr   +   s        c                 T     [         R                  " U 5      $ ! [         a    U s $ f = fN)oswaitstatus_to_exitcode
ValueError)statuss    r   r#   r#   0   s.    ((00  	s    ''c            	          ^  \ rS rSrSrSU 4S jjrU 4S jrS rS rS r	S	 r
S
 r  SS jr  SS jr SS jrS r SSSSSSS.S jjr SSSSSSSSS.S jjrS rS rS rS rU 4S jrSrU =r$ )_UnixSelectorEventLoop:   z\Unix event loop.

Adds signal handling and UNIX Domain Socket support to SelectorEventLoop.
Nc                 @   > [         TU ]  U5        0 U l        0 U l        g r!   )super__init___signal_handlers_unix_server_sockets)selfselector	__class__s     r   r+   _UnixSelectorEventLoop.__init__@   s     " "$&!r   c                 H  > [         TU ]  5         [        R                  " 5       (       d.  [	        U R
                  5       H  nU R                  U5        M     g U R
                  (       a:  [        R                  " SU < S3[        U S9  U R
                  R                  5         g g )NzClosing 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.   sigr0   s     r   r5   _UnixSelectorEventLoop.closeE   s      ""D112**3/ 3 $$ 1$ :H I .%)	+
 %%++- %r   c                 J    U H  nU(       d  M  U R                  U5        M     g r!   )_handle_signal)r.   datar   s      r   _process_self_data)_UnixSelectorEventLoop._process_self_dataS   s     F'	 r   c                    [         R                  " U5      (       d  [         R                  " U5      (       a  [        S5      eU R	                  U5        U R                  5          [        R                  " U R                  R                  5       5        [        R                  " X#U S5      nXPR                   U'    [        R                  " U["        5        [        R$                  " US5        g! [        [        4 a  n[        [        U5      5      eSnAff = f! [         a  nU R                   U	 U R                   (       dL   [        R                  " S5        O4! [        [        4 a!  n[&        R(                  " SU5         SnAOSnAff = fUR*                  [*        R,                  :X  a  [        SU S35      ee SnAff = f)zAdd 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_handler)_UnixSelectorEventLoop.add_signal_handlerZ   ss    ""8,,..x88 8 9 93	)
   !3!3!56 xtT:%+c"	 MM#/0 U+ G$ 	)s3x((	)  	%%c*((F((,"G, FKK >EEF yyELL("T#.?#@AA	sZ   $.C, 92D ,D<DD
F?"F:EF:F	(F?F:F		1F::F?c                     U R                   R                  U5      nUc  gUR                  (       a  U R                  U5        gU R	                  U5        g)z2Internal helper that is the actual signal handler.N)r,   get
_cancelledr9   _add_callback_signalsafe)r.   r>   r^   s      r   rA   %_UnixSelectorEventLoop._handle_signal   sE    &&**3/>&&s+))&1r   c                 4   U R                  U5         U R                  U	 U[        R                  :X  a  [        R
                  nO[        R                  n [        R                  " X5        U R                  (       d   [        R                  " S5        gg! [         a     gf = f! [         a3  nUR                  [        R                  :X  a  [        SU S35      ee SnAff = f! [        [        4 a!  n[        R                  " SU5         SnAgSnAff = f)zgRemove a handler for a signal.  UNIX only.

Return True if a signal handler was removed, False if not.
FrH   rI   NrF   rG   T)rM   r,   KeyErrorrO   SIGINTdefault_int_handlerSIG_DFLrS   rY   rZ   rT   rP   r$   r   rX   )r.   r>   handlerr]   s       r   r9   ,_UnixSelectorEventLoop.remove_signal_handler   s    
 	3	%%c* &--00GnnG	MM#' $$A$$R( -  		  	yyELL("T#.?#@AA		 ( A:C@@AsA   B B& >C& 
B#"B#&
C#0.CC#&D6DDc                     [        U[        5      (       d  [        SU< 35      eU[        R                  " 5       ;  a  [        SU 35      eg)zInternal 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.
zsig must be an int, not zinvalid signal number N)
isinstanceintrL   rO   valid_signalsr$   )r.   r>   s     r   rM   $_UnixSelectorEventLoop._check_signal   sM     #s##6sg>??f**,,5cU;<< -r   c                     [        XX#U5      $ r!   )_UnixReadPipeTransportr.   pipeprotocolwaiterextras        r   _make_read_pipe_transport0_UnixSelectorEventLoop._make_read_pipe_transport   s    %d(EJJr   c                     [        XX#U5      $ r!   )_UnixWritePipeTransportru   s        r   _make_write_pipe_transport1_UnixSelectorEventLoop._make_write_pipe_transport   s    &t8UKKr   c	                   #    [         R                  " 5          [         R                  " S[        5        [        R
                  " 5       n
S S S 5        W
   U
R                  5       (       d  [        S5      eU R                  5       n[        XX#XEXg4XS.U	D6nU
R                  UR                  5       U R                  U5         UI S h  vN    S S S 5        U$ ! , (       d  f       N= f N ! [        [        4 a    e [         a+    UR!                  5         UR#                  5       I S h  vN    e f = f! , (       d  f       W$ = f7f)NignorezRasyncio.get_child_watcher() is not activated, subprocess support is not installed.)rx   ry   )r:   catch_warningssimplefilterDeprecationWarningr   get_child_watcher	is_activerT   create_future_UnixSubprocessTransportadd_child_handlerget_pid_child_watcher_callback
SystemExitKeyboardInterruptBaseExceptionr5   _wait)r.   rw   r\   shellstdinstdoutstderrbufsizery   kwargswatcherrx   transps                r   _make_subprocess_transport1_UnixSelectorEventLoop._make_subprocess_transport   s)     $$&!!(,>?..0G ' $$&&
 # $G H H'')F-dd,166396 /56F %%fnn&6$($@$@&J! 0 9 '&(  12   lln$$' W0 se   E1C	
EA-D1C)C'C)
E
C$ E'C))=D.&D)'D..D11
E ;Ec                 <    U R                  UR                  U5        g r!   )call_soon_threadsafe_process_exited)r.   pid
returncoder   s       r   r   ._UnixSelectorEventLoop._child_watcher_callback   s    !!&"8"8*Er   )sslsockserver_hostnamessl_handshake_timeoutssl_shutdown_timeoutc          	        #    Ub  [        U[        5      (       d   eU(       a  Uc  [        S5      eO*Ub  [        S5      eUb  [        S5      eUb  [        S5      eUb  Ub  [        S5      e[        R                  " U5      n[
        R
                  " [
        R                  [
        R                  S5      n UR                  S5        U R                  XB5      I S h  vN   OjUc  [        S5      eUR                  [
        R                  :w  d  UR                  [
        R                  :w  a  [        S	U< 35      eUR                  S5        U R                  XAX5UUS
9I S h  vN u  pX4$  N!   UR                  5         e = f N!7f)Nz/you have to pass server_hostname when using sslz+server_hostname is only meaningful with ssl1ssl_handshake_timeout is only meaningful with ssl0ssl_shutdown_timeout is only meaningful with ssl3path and sock can not be specified at the same timer   Fzno path and sock were specified.A UNIX Domain Stream Socket was expected, got )r   r   )ro   rU   r$   r"   fspathsocketAF_UNIXSOCK_STREAMsetblockingsock_connectr5   familytype_create_connection_transport)
r.   protocol_factorypathr   r   r   r   r   	transportrw   s
             r   create_unix_connection-_UnixSelectorEventLoop.create_unix_connection   s     &*_c*J*JJJ& EG G ' * !NOO$0 GI I#/ FH H  IK K 99T?D==1C1CQGD  '''333 | !BCCv~~-II!3!33 DTHMO OU#$($E$EC"7!5 %F %7 7	 ""% 4

7s=   B6F9%E/ E-E/ #B F#F$	F-E/ /FFd   T)r   backlogr   r   r   start_servingcleanup_socketc          	        #    [        U[        5      (       a  [        S5      eUb  U(       d  [        S5      eUb  U(       d  [        S5      eUb  Ub  [        S5      e[        R
                  " U5      n[        R                  " [        R                  [        R                  5      nUS   S;  aP   [        R                  " [        R                  " U5      R                  5      (       a  [        R                  " U5         UR#                  U5        OYUc  [        S
5      eUR*                  [        R                  :w  d  UR,                  [        R                  :w  a  [        SU< 35      eU	(       aG  UR/                  5       nUS   S;  a.   [        R                  " U5      R0                  U R2                  U'   UR5                  S5        [6        R8                  " X/UXTUU5      nU(       a.  UR;                  5         [<        R>                  " S5      I S h  vN   U$ ! [         a     GN*[         a"  n
[        R                   " SX*5         S n
A
GNPS n
A
ff = f! [         aV  nUR%                  5         UR&                  [&        R(                  :X  a"  SU< S	3n[        [&        R(                  U5      S ee S nAf  UR%                  5         e = f! [         a     GNf = f N7f)Nz*ssl argument must be an SSLContext or Noner   r   r   r   )r    z2Unable to check or remove stale UNIX socket %r: %rzAddress z is already in usez-path was not specified, and no sock specifiedr   F) ro   boolrL   r$   r"   r   r   r   r   statS_ISSOCKst_moderemoveFileNotFoundErrorrS   r   errorbindr5   rY   
EADDRINUSEr   r   getsocknamest_inor-   r   r   Server_start_servingr   sleep)r.   r   r   r   r   r   r   r   r   r   errr]   msgservers                 r   create_unix_server)_UnixSelectorEventLoop.create_unix_server  s     c4  HII ,SCE E  +CBD D  IK K 99T?D==1C1CDD Awk)6}}RWWT]%:%:;;		$		$ | CE E v~~-II!3!33 DTHMO O ##%DAwk)68ggdm6J6JD--d3 	##D&2B$'2G$8: !!# ++a.  e )  6LL "*+/6 66  

99 0 00 %TH,>?C!%"2"2C8dB

" )  !s   B.K1AH I A:K-K :AKKK
I'K*	I3I
KIK
K	"AJ33K		K
KKKKc           
        #     [         R                     UR                  5       n [         R                  " U5      R                  nU(       a  UOUnU(       d  gU R                  5       n	U R                  U	S XX4US5        U	I S h  vN $ ! [         a    [        R                  " S5      ef = f! [        [        R                  4 a  n[        R                  " S5      eS nAff = f! [         a    [        R                  " S5      ef = f N7f)Nzos.sendfile() is not availableznot a regular filer   )r"   sendfileAttributeErrorr	   SendfileNotAvailableErrorrR   ioUnsupportedOperationfstatst_sizerS   r   _sock_sendfile_native_impl)
r.   r   fileoffsetcountrR   r   fsize	blocksizefuts
             r   _sock_sendfile_native,_UnixSelectorEventLoop._sock_sendfile_nativem  s     	2KK	M[[]F	MHHV$,,E #E	  "''T4(.y!	Ey%  	26602 2	2
  7 78 	M667KLL	M  	M667KLL	M sV   DB	 B-  C% >DD	D	!B**D-C"CC""D%!DDc	                    UR                  5       n	Ub  U R                  U5        UR                  5       (       a  U R                  XEU5        g U(       a.  Xh-
  nUS::  a$  U R                  XEU5        UR	                  U5        g [        U[        R                  S-  S-   5      n [        R                  " XXW5      n
U
S:X  a$  U R                  XEU5        UR	                  U5        g XZ-  nX-  nUc  U R                  X5        U R                  XR                  UXUXVXx5
        g ! [        [        4 a7    Uc  U R                  X5        U R                  XR                  UXUXVXx5
         g [         a  nUbR  UR                   [         R"                  :X  a4  [%        U5      [&        La"  ['        S[         R"                  5      nXl        UnUS:X  a>  [*        R,                  " S5      nU R                  XEU5        UR/                  U5         S nAg U R                  XEU5        UR/                  U5         S nAg S nAf[0        [2        4 a    e [4         a-  nU R                  XEU5        UR/                  U5         S nAg S nAff = f)Nr      r   zsocket is not connectedzos.sendfile call failed)rR   remove_writer	cancelled_sock_sendfile_update_filepos
set_resultminr6   maxsizer"   r   _sock_add_cancellation_callback
add_writerr   BlockingIOErrorInterruptedErrorrS   rY   ENOTCONNr   ConnectionError	__cause__r	   r   set_exceptionr   r   r   )r.   r   registered_fdr   rR   r   r   r   
total_sentfdsentr]   new_excr   s                 r   r   1_UnixSelectorEventLoop._sock_sendfile_native_impl  sA   [[]$
 }-==??..vzJ*IA~226:Nz* 	3;;>A#56	1	F;;r6=DJ qy226:Nz*"
 (88C$C$CS "& &yF[  !12 	B$44S?OOB ? ?f"9B  	')II/I_4
 *-u~~?$'!Q
 !::-/226:N!!#&&226:N!!#&&-. 	 	#..vzJc""	#s2   #D! !AI;'	I;0BH1	#H11I;#I66I;c                 \    US:  a&  [         R                  " X[         R                  5        g g Nr   )r"   lseekSEEK_SET)r.   rR   r   r   s       r   r   4_UnixSelectorEventLoop._sock_sendfile_update_filepos  s     >HHVR[[1 r   c                 8   ^ ^ U U4S jnUR                  U5        g )Nc                    > U R                  5       (       a)  TR                  5       nUS:w  a  TR                  U5        g g g )NrF   )r   rR   r   )r   r   r.   r   s     r   cbB_UnixSelectorEventLoop._sock_add_cancellation_callback.<locals>.cb  s8    }}[[]8&&r*  r   )add_done_callback)r.   r   r   r   s   ` ` r   r   6_UnixSelectorEventLoop._sock_add_cancellation_callback  s    	+
 	b!r   c                   > XR                   ;   a  UR                  5       nOS n[        TU ]  U5        UbY  U R                   U   nU R                   U	  [        R
                  " U5      R                  U:X  a  [        R                  " U5        g g g ! [         a     g [         a!  n[        R                  " SX$5         S nAg S nAff = f)Nz/Unable to clean up listening UNIX socket %r: %r)r-   r   r*   _stop_servingr"   r   r   unlinkr   rS   r   r   )r.   r   r   prev_inor   r0   s        r   r  $_UnixSelectorEventLoop._stop_serving  s    ,,,##%DDd#006H))$/2774=''83IIdO 4	  %  2 &'+2 22s   :B 
C	C%CC)r,   r-   r!   NN)__name__
__module____qualname____firstlineno____doc__r+   r5   rC   r`   rA   r9   rM   rz   r~   r   r   r   r   r   r   r   r   r  __static_attributes____classcell__r0   s   @r   r'   r'   :   s    
'
.(+Z2@
= @D(,K AE)-L 04BF *.0#4 "&!%0#f *.Ps"&!%tPd.GFR2"2 2r   r'   c                      ^  \ rS rSrSrSU 4S jjrS rS rS rS r	S r
S	 rS
 rS rS rS r\R"                  4S jrSS jrS rS rSrU =r$ )rt   i  i   c                 V  > [         TU ]  U5        X R                  S'   Xl        X l        UR                  5       U l        X0l        SU l        SU l	        [        R                  " U R                  5      R                  n[        R                  " U5      (       dV  [        R                  " U5      (       d;  [        R                   " U5      (       d   S U l        S U l        S U l        [#        S5      e[        R$                  " U R                  S5        U R                  R'                  U R                  R(                  U 5        U R                  R'                  U R*                  U R                  U R,                  5        Ub,  U R                  R'                  [.        R0                  US 5        g g )Nrv   Fz)Pipe transport is for pipes/sockets only.)r*   r+   _extra_loop_piperR   _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.   looprv   rw   rx   ry   moder0   s          r   r+   _UnixReadPipeTransport.__init__  s/   "F

{{}!xx%--d##d##T""DJDL!DNHII
e,

T^^;;TB

T--!\\4+;+;	=JJ  !E!E!'/ r   c                 f    U R                  5       (       d  g U R                  R                  X5        g r!   )
is_readingr  r  )r.   r   r[   s      r   r  "_UnixReadPipeTransport._add_reader  s$      

r,r   c                 T    U R                   (       + =(       a    U R                  (       + $ r!   )r  r  r.   s    r   r&  !_UnixReadPipeTransport.is_reading  s    <<5$55r   c                    U R                   R                  /nU R                  c  UR                  S5        O"U R                  (       a  UR                  S5        UR                  SU R
                   35        [        U R                  SS 5      nU R                  b]  UbZ  [        R                  " X R
                  [        R                  5      nU(       a  UR                  S5        OBUR                  S5        O0U R                  b  UR                  S5        OUR                  S5        SR                  S	R                  U5      5      $ )
Nclosedclosingfd=	_selectorpollingidleopen<{}> )r0   r	  r  appendr  r  getattrr  r   _test_selector_event	selectors
EVENT_READformatjoin)r.   rX   r/   r0  s       r   __repr___UnixReadPipeTransport.__repr__  s    ''(::KK!]]KK	"c$,,()4::{D9::!h&:%::,,	(<(<>GI&F#ZZ#KKKK!}}SXXd^,,r   c                     [         R                  " U R                  U R                  5      nU(       a  U R                  R                  U5        g U R                  R                  5       (       a  [        R                  " SU 5        SU l
        U R                  R                  U R                  5        U R                  R                  U R                  R                  5        U R                  R                  U R                  S 5        g ! [        [         4 a     g ["         a  nU R%                  US5         S nAg S nAff = f)N%r was closed by peerTz"Fatal read error on pipe transport)r"   readr  max_sizer  data_receivedr  	get_debugr   rX   r  _remove_readerr  eof_received_call_connection_lostr   r   rS   _fatal_error)r.   rB   r]   s      r   r   "_UnixReadPipeTransport._read_ready.  s    	G774<<7D ,,T2::''))KK 7> $

))$,,7

$$T^^%@%@A

$$T%?%?F  !12 	 	Ic#GHH	Is   +D D?	D?#D::D?c                     U R                  5       (       d  g SU l        U R                  R                  U R                  5        U R                  R                  5       (       a  [        R                  " SU 5        g g )NTz%r pauses reading)r&  r  r  rD  r  rC  r   debugr)  s    r   pause_reading$_UnixReadPipeTransport.pause_reading@  sV      

!!$,,/::!!LL,d3 "r   c                 &   U R                   (       d  U R                  (       d  g SU l        U R                  R                  U R                  U R
                  5        U R                  R                  5       (       a  [        R                  " SU 5        g g )NFz%r resumes reading)	r  r  r  r  r  r   rC  r   rJ  r)  s    r   resume_reading%_UnixReadPipeTransport.resume_readingH  s^    ==

t||T-=-=>::!!LL-t4 "r   c                     Xl         g r!   r  r.   rw   s     r   set_protocol#_UnixReadPipeTransport.set_protocolP      !r   c                     U R                   $ r!   rQ  r)  s    r   get_protocol#_UnixReadPipeTransport.get_protocolS      ~~r   c                     U R                   $ r!   r  r)  s    r   
is_closing!_UnixReadPipeTransport.is_closingV      }}r   c                 J    U R                   (       d  U R                  S 5        g g r!   )r  _closer)  s    r   r5   _UnixReadPipeTransport.closeY  s    }}KK r   c                 t    U R                   b+  U" SU < 3[        U S9  U R                   R                  5         g g Nzunclosed transport r3   r  r<   r5   r.   _warns     r   __del___UnixReadPipeTransport.__del__]  5    ::!'x0/$OJJ "r   c                 L   [        U[        5      (       aT  UR                  [        R                  :X  a6  U R                  R                  5       (       a  [        R                  " SXSS9  O*U R                  R                  UUU U R                  S.5        U R                  U5        g Nz%r: %sTexc_info)message	exceptionr   rw   )ro   rS   rY   EIOr  rC  r   rJ  call_exception_handlerr  r`  r.   r]   rn  s      r   rG  #_UnixReadPipeTransport._fatal_errorb  sw    sG$$eii)?zz##%%XttDJJ--" ! NN	/  	Cr   c                     SU l         U R                  R                  U R                  5        U R                  R	                  U R
                  U5        g NT)r  r  rD  r  r  rF  r.   r]   s     r   r`  _UnixReadPipeTransport._closep  s9    

!!$,,/

T77=r   c                     U R                   R                  U5        U R                  R                  5         S U l        S U l         S U l        g ! U R                  R                  5         S U l        S U l         S U l        f = fr!   r  connection_lostr  r5   r  rv  s     r   rF  ,_UnixReadPipeTransport._call_connection_lostu  g    	NN**3/JJDJ!DNDJ JJDJ!DNDJ   A 1A>)r  r  r  r  r  r  r  zFatal error on pipe transport)r	  r
  r  r  rA  r+   r  r&  r<  r   rK  rN  rS  rW  r\  r5   r:   r;   rg  rG  r`  rF  r  r  r  s   @r   rt   rt     sb    H/<-
6-*G$45" %MM 
>
 r   rt   c                      ^  \ rS rSrSU 4S jjrS rS rS rS rS r	S r
S	 rS
 rS rS rS r\R"                  4S jrS rSS jrSS jrS rSrU =r$ )r}   i  c                   > [         T
U ]  XQ5        X R                  S'   X l        UR	                  5       U l        X0l        [        5       U l        SU l	        SU l
        [        R                  " U R
                  5      R                  n[        R                  " U5      n[        R                   " U5      n[        R"                  " U5      n	U(       d.  U(       d'  U	(       d   S U l        S U l        S U l        [%        S5      e[        R&                  " U R
                  S5        U R(                  R+                  U R                  R,                  U 5        U	(       d+  U(       ai  [.        R0                  R3                  S5      (       dE  U R(                  R+                  U R(                  R4                  U R
                  U R6                  5        Ub,  U R(                  R+                  [8        R:                  US 5        g g )Nrv   r   Fz?Pipe transport is only for pipes, sockets and character devicesaix)r*   r+   r  r  rR   r  r  	bytearray_buffer
_conn_lostr  r"   r   r   r   r  r  r   r$   r  r  r  r  r6   platform
startswithr  r   r
   r!  )r.   r"  rv   rw   rx   ry   r#  is_charis_fifo	is_socketr0   s             r   r+    _UnixWritePipeTransport.__init__  sd   %"F
{{}! {xx%--,,t$--%MM$'	7iDJDL!DN D E E 	e,

T^^;;TB
 )@)@)G)GJJ  !7!7!%t/?/?A JJ  !E!E!'/ r   c                    U R                   R                  /nU R                  c  UR                  S5        O"U R                  (       a  UR                  S5        UR                  SU R
                   35        [        U R                  SS 5      nU R                  b  Ub~  [        R                  " X R
                  [        R                  5      nU(       a  UR                  S5        OUR                  S5        U R                  5       nUR                  SU 35        O0U R                  b  UR                  S5        OUR                  S5        S	R                  S
R                  U5      5      $ )Nr,  r-  r.  r/  r0  r1  zbufsize=r2  r3  r4  )r0   r	  r  r5  r  r  r6  r  r   r7  r8  EVENT_WRITEget_write_buffer_sizer:  r;  )r.   rX   r/   r0  r   s        r   r<   _UnixWritePipeTransport.__repr__  s	   ''(::KK!]]KK	"c$,,()4::{D9::!h&:%::,,	(=(=?GI&F#002GKK(7),-ZZ#KKKK!}}SXXd^,,r   c                 ,    [        U R                  5      $ r!   )lenr  r)  s    r   r  -_UnixWritePipeTransport.get_write_buffer_size  s    4<<  r   c                     U R                   R                  5       (       a  [        R                  " SU 5        U R                  (       a  U R                  [        5       5        g U R                  5         g )Nr?  )r  rC  r   rX   r  r`  BrokenPipeErrorr)  s    r   r   #_UnixWritePipeTransport._read_ready  sC    ::!!KK/6<<KK)*KKMr   c                    [        U[        [        [        45      (       d   [	        U5      5       e[        U[        5      (       a  [        U5      nU(       d  g U R
                  (       d  U R                  (       aJ  U R
                  [        R                  :  a  [        R                  " S5        U =R
                  S-  sl        g U R                  (       dv   [        R                  " U R                  U5      nU[+        U5      :X  a  g US:  a  [        U5      US  nU R,                  R/                  U R                  U R0                  5        U =R                  U-  sl        U R3                  5         g ! [        [         4 a    Sn N["        [$        4 a    e [&         a1  nU =R
                  S-  sl        U R)                  US5         S nAg S nAff = f)Nz=pipe closed by peer or os.write(pipe, data) raised exception.r   r   #Fatal write error on pipe transport)ro   bytesr  
memoryviewreprr  r  r   !LOG_THRESHOLD_FOR_CONNLOST_WRITESr   warningr  r"   writer  r   r   r   r   r   rG  r  r  _add_writer_write_ready_maybe_pause_protocol)r.   rB   nr]   s       r   r  _UnixWritePipeTransport.write  s]   $	: >??KdK?dI&&d#D??dmm)"M"MM  H IOOq O||	HHT\\40 CI~Q!$'+JJ""4<<1B1BC""$ $%56  12   1$!!#'LMs   !E2 2GG'GGc                 T   U R                   (       d   S5       e [        R                  " U R                  U R                   5      nU[	        U R                   5      :X  a  U R                   R                  5         U R                  R                  U R                  5        U R                  5         U R                  (       a6  U R                  R                  U R                  5        U R                  S 5        g US:  a  U R                   S U2	 g g ! [        [        4 a     g [        [        4 a    e [          ap  nU R                   R                  5         U =R"                  S-  sl        U R                  R                  U R                  5        U R%                  US5         S nAg S nAff = f)NzData should not be emptyr   r   r  )r  r"   r  r  r  r=   r  _remove_writer_maybe_resume_protocolr  rD  rF  r   r   r   r   r   r  rG  )r.   r  r]   s      r   r  $_UnixWritePipeTransport._write_ready  s@   ||777|	%t||4A C%%""$

))$,,7++-==JJ--dll;..t4QLL!$ )  !12 	-. 	 	JLL OOq O JJ%%dll3c#HII	Js   +D F'F'7A&F""F'c                     gru  r   r)  s    r   can_write_eof%_UnixWritePipeTransport.can_write_eof
      r   c                    U R                   (       a  g U R                  (       d   eSU l         U R                  (       dL  U R                  R	                  U R
                  5        U R                  R                  U R                  S 5        g g ru  )r  r  r  r  rD  r  r  rF  r)  s    r   	write_eof!_UnixWritePipeTransport.write_eof  s[    ==zzz||JJ%%dll3JJ  !;!;TB r   c                     Xl         g r!   rQ  rR  s     r   rS  $_UnixWritePipeTransport.set_protocol  rU  r   c                     U R                   $ r!   rQ  r)  s    r   rW  $_UnixWritePipeTransport.get_protocol  rY  r   c                     U R                   $ r!   r[  r)  s    r   r\  "_UnixWritePipeTransport.is_closing  r^  r   c                 d    U R                   b#  U R                  (       d  U R                  5         g g g r!   )r  r  r  r)  s    r   r5   _UnixWritePipeTransport.close  s$    ::!$--NN +8!r   c                 t    U R                   b+  U" SU < 3[        U S9  U R                   R                  5         g g rc  rd  re  s     r   rg  _UnixWritePipeTransport.__del__$  ri  r   c                 &    U R                  S 5        g r!   )r`  r)  s    r   abort_UnixWritePipeTransport.abort)  s    Dr   c                    [        U[        5      (       a6  U R                  R                  5       (       a  [        R
                  " SXSS9  O*U R                  R                  UUU U R                  S.5        U R                  U5        g rk  )	ro   rS   r  rC  r   rJ  rq  r  r`  rr  s      r   rG  $_UnixWritePipeTransport._fatal_error,  sh    c7##zz##%%XttDJJ--" ! NN	/  	Cr   c                 H   SU l         U R                  (       a%  U R                  R                  U R                  5        U R                  R                  5         U R                  R                  U R                  5        U R                  R                  U R                  U5        g ru  )	r  r  r  r  r  r=   rD  r  rF  rv  s     r   r`  _UnixWritePipeTransport._close:  sf    <<JJ%%dll3

!!$,,/

T77=r   c                     U R                   R                  U5        U R                  R                  5         S U l        S U l         S U l        g ! U R                  R                  5         S U l        S U l         S U l        f = fr!   ry  rv  s     r   rF  -_UnixWritePipeTransport._call_connection_lostB  r|  r}  )r  r  r  r  r  r  r  r  r~  r!   )r	  r
  r  r  r+   r<  r  r   r  r  r  r  rS  rW  r\  r5   r:   r;   rg  r  rG  r`  rF  r  r  r  s   @r   r}   r}     si    #/J-0!!%F%8C"
 %MM 
> r   r}   c                       \ rS rSrS rSrg)r   iL  c           
         S nU[         R                  :X  a;  [        R                  R	                  S5      (       a  [
        R                  " 5       u  p8 [         R                  " U4X#XESUS.UD6U l        Ub:  UR                  5         [        UR                  5       SUS9U R                  l        S nUb!  UR                  5         UR                  5         g g ! Ub!  UR                  5         UR                  5         f f = f)Nr  F)r   r   r   r   universal_newlinesr   wb)	buffering)
subprocessPIPEr6   r  r  r   
socketpairPopen_procr5   r2  detachr   )	r.   r\   r   r   r   r   r   r   stdin_ws	            r   _start_UnixSubprocessTransport._startN  s    JOO#(?(?(F(F
 $..0NE	 #))E!v#('E=CEDJ "#'(8$'#R

 " #w" #s   AC &C<)r  N)r	  r
  r  r  r  r  r   r   r   r   r   L  s     r   r   c                   L    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rSrg)r   id  a  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.
Nc                 Z    U R                   [        :w  a  [        R                  " SSSS9  g g )Nr   P{name!r} is deprecated as of Python 3.12 and will be removed in Python {remove}.      r   )r
  r	  r:   _deprecated)clss    r   __init_subclass__&AbstractChildWatcher.__init_subclass__{  s,    >>X%  !7;%,. &r   c                     [        5       e)zRegister 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   r[   r\   s       r   r   &AbstractChildWatcher.add_child_handler  s     "##r   c                     [        5       e)zRemoves 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_handler)AbstractChildWatcher.remove_child_handler  s     "##r   c                     [        5       e)zAttach 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_loop AbstractChildWatcher.attach_loop  s     "##r   c                     [        5       e)z\Close the watcher.

This must be called to make sure that any underlying resource is freed.
r  r)  s    r   r5   AbstractChildWatcher.close  s    
 "##r   c                     [        5       e)zReturn ``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  r)  s    r   r   AbstractChildWatcher.is_active  s     "##r   c                     [        5       e)z\Enter the watcher's context and allow starting new processes

This function must return selfr  r)  s    r   	__enter__AbstractChildWatcher.__enter__  s     "##r   c                     [        5       e)zExit the watcher's contextr  r.   abcs       r   __exit__AbstractChildWatcher.__exit__  s    !##r   r   )returnN)r	  r
  r  r  r  r  r   r  r  r5   r   r  r  r  r   r   r   r   r   d  s/    ,.	$$$$$$$r   r   c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)r   i  a  Child 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                     U $ r!   r   r)  s    r   r  PidfdChildWatcher.__enter__      r   c                     g r!   r   )r.   exc_type	exc_valueexc_tracebacks       r   r  PidfdChildWatcher.__exit__      r   c                     gru  r   r)  s    r   r   PidfdChildWatcher.is_active  r  r   c                     g r!   r   r)  s    r   r5   PidfdChildWatcher.close  r  r   c                     g r!   r   r  s     r   r  PidfdChildWatcher.attach_loop  r  r   c                     [         R                  " 5       n[        R                  " U5      nUR	                  XPR
                  XX#5        g r!   )r   get_running_loopr"   
pidfd_openr  _do_wait)r.   r   r[   r\   r"  pidfds         r   r   #PidfdChildWatcher.add_child_handler  s4    &&(c"s8Jr   c                 *   [         R                  " 5       nUR                  U5         [        R                  " US5      u  pg[        U5      n[        R                  " U5        U" X/UQ76   g ! [         a    Sn[        R                  " SU5         NEf = f)Nr      zJchild process pid %d exit status already read:  will report returncode 255)
r   r  rD  r"   waitpidr#   ChildProcessErrorr   r  r5   )	r.   r   r	  r[   r\   r"  _r%   r   s	            r   r  PidfdChildWatcher._do_wait  s    &&(E"	8

3*IA 07J
(4( ! 	 JNN.		s   A, ,#BBc                     gru  r   r  s     r   r  &PidfdChildWatcher.remove_child_handler       r   r   N)r	  r
  r  r  r  r  r  r   r5   r  r   r  r  r  r   r   r   r   r     s0    	K
)&r   r   c                   >    \ rS rSrS rS rS rS rS rS r	S r
S	rg
)BaseChildWatcheri  c                      S U l         0 U l        g r!   )r  
_callbacksr)  s    r   r+   BaseChildWatcher.__init__  s    
r   c                 &    U R                  S 5        g r!   )r  r)  s    r   r5   BaseChildWatcher.close  s    r   c                 `    U R                   S L=(       a    U R                   R                  5       $ r!   )r  
is_runningr)  s    r   r   BaseChildWatcher.is_active  s#    zz%A$***?*?*AAr   c                     [        5       er!   r  )r.   expected_pids     r   _do_waitpidBaseChildWatcher._do_waitpid       !##r   c                     [        5       er!   r  r)  s    r   _do_waitpid_all BaseChildWatcher._do_waitpid_all  r"  r   c                    Ub!  [        U[        R                  5      (       d   eU R                  b/  Uc,  U R                  (       a  [
        R                  " S[        5        U R                  b)  U R                  R                  [        R                  5        Xl        Ub;  UR                  [        R                  U R                  5        U R                  5         g g )NzCA loop is being detached from a child watcher with pending handlers)ro   r   AbstractEventLoopr  r  r:   r;   RuntimeWarningr9   rO   SIGCHLDr`   	_sig_chldr$  r  s     r   r  BaseChildWatcher.attach_loop  s    |z$0H0HIIII::!dltMM= 
 ::!JJ,,V^^<
##FNNDNNC   " r   c                      U R                  5         g ! [        [        4 a    e [         a(  nU R                  R                  SUS.5         S nAg S nAff = f)N$Unknown exception in SIGCHLD handler)rn  ro  )r$  r   r   r   r  rq  rv  s     r   r*  BaseChildWatcher._sig_chld  sX    	  "-. 	 	 JJ--A /  		s    AAA)r  r  N)r	  r
  r  r  r+   r5   r   r   r$  r  r*  r  r   r   r   r  r    s&    B$$#(r   r  c                   \   ^  \ rS rSrSrU 4S jrU 4S jrS rS rS r	S r
S	 rS
 rSrU =r$ )r   i)  aL  '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                 N   > [         TU ]  5         [        R                  " SSSS9  g )Nr   r  r  r  )r*   r+   r:   r  r.   r0   s    r   r+   SafeChildWatcher.__init__4  s'    /;%,	.r   c                 V   > U R                   R                  5         [        TU ]  5         g r!   )r  r=   r*   r5   r1  s    r   r5   SafeChildWatcher.close;  s    r   c                     U $ r!   r   r)  s    r   r  SafeChildWatcher.__enter__?  r  r   c                     g r!   r   r  s       r   r  SafeChildWatcher.__exit__B  r  r   c                 F    X#4U R                   U'   U R                  U5        g r!   )r  r   r  s       r   r   "SafeChildWatcher.add_child_handlerE  s#     (/ 	r   c                 @     U R                   U	 g! [         a     gf = fNTFr  rh   r  s     r   r  %SafeChildWatcher.remove_child_handlerK  (    	$ 		    
c                 ^    [        U R                  5       H  nU R                  U5        M     g r!   r8   r  r   r  s     r   r$   SafeChildWatcher._do_waitpid_allR  s#    (CS! )r   c                 &   US:  d   e [         R                  " U[         R                  5      u  p#US:X  a  g [        U5      nU R                  R                  5       (       a  [        R                  " SX5         U R                  R                  U5      u  pVU" X$/UQ76   g ! [         a    UnSn[        R                  " SU5         NOf = f! [         a:    U R                  R                  5       (       a  [        R                  " SUSS9   g  g f = f)Nr   $process %s exited with returncode %sr  8Unknown child process pid %d, will report returncode 255'Child watcher got an unexpected pid: %rTrl  )r"   r  WNOHANGr#   r  rC  r   rJ  r  r  r  poprh   )r.   r  r   r%   r   r[   r\   s          r   r   SafeChildWatcher._do_waitpidW  s    a	7**\2::>KC ax/7Jzz##%%C)7		-!__005NH S,t,7 ! 	 CJNNJ	(  	3 zz##%%H"T3 &	3s#   'B! :C !%C	C	?DDr   )r	  r
  r  r  r  r+   r5   r  r  r   r  r$  r   r  r  r  s   @r   r   r   )  s5    ."
 -  -r   r   c                   V   ^  \ rS rSrSrU 4S jrU 4S jrS rS rS r	S r
S	 rS
rU =r$ )r   iz  a?  '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U ]  5         [        R                  " 5       U l        0 U l        SU l        [        R                  " SSSS9  g )Nr   r   r  r  r  )	r*   r+   	threadingLock_lock_zombies_forksr:   r  r1  s    r   r+   FastChildWatcher.__init__  sC    ^^%
/;%,	.r   c                    > U R                   R                  5         U R                  R                  5         [        TU ]  5         g r!   )r  r=   rP  r*   r5   r1  s    r   r5   FastChildWatcher.close  s,    r   c                 ~    U R                      U =R                  S-  sl        U sS S S 5        $ ! , (       d  f       g = f)Nr   )rO  rQ  r)  s    r   r  FastChildWatcher.__enter__  s$    ZZKK1K ZZs   .
<c                 ^   U R                      U =R                  S-  sl        U R                  (       d  U R                  (       d
   S S S 5        g [        U R                  5      nU R                  R	                  5         S S S 5        [
        R                  " SW5        g ! , (       d  f       N&= f)Nr   z5Caught subprocesses termination from unknown pids: %s)rO  rQ  rP  rU   r=   r   r  )r.   r  r  r  collateral_victimss        r   r  FastChildWatcher.__exit__  sp    ZZKK1K{{$--	 Z "%T]]!3MM!  	C	  Zs   9B/B
B,c                    U R                   (       d   S5       eU R                      U R                  R                  U5      n S S S 5        U" UW/UQ76   g ! [         a    X#4U R
                  U'    S S S 5        g f = f! , (       d  f       NA= f)NzMust use the context manager)rQ  rO  rP  rI  rh   r  )r.   r   r[   r\   r   s        r   r   "FastChildWatcher.add_child_handler  s}    {{:::{ZZ!]]..s3
  	j(4(  '/~$ Z Zs(   A>AA;0A>:A;;A>>
Bc                 @     U R                   U	 g! [         a     gf = fr<  r=  r  s     r   r  %FastChildWatcher.remove_child_handler  r?  r@  c                      [         R                  " S[         R                  5      u  pUS:X  a  g [        U5      nU R
                      U R                  R                  U5      u  pEU R                  R                  5       (       a  [        R                  " SX5        S S S 5        Wc  [        R                  " SX5        O	U" X/WQ76   M  ! [         a     g f = f! [         af    U R                  (       aP  X0R                  U'   U R                  R                  5       (       a  [        R                  " SX5         S S S 5        GME  S n Nf = f! , (       d  f       N= f)NrF   r   rE  z,unknown process %s exited with returncode %sz8Caught subprocess termination from unknown pid: %d -> %d)r"   r  rH  r#   r  rO  r  rI  r  rC  r   rJ  rh   rQ  rP  r  )r.   r   r%   r   r[   r\   s         r   r$   FastChildWatcher._do_waitpid_all  s0    
< jjRZZ8
 !83F;
6%)__%8%8%=NH zz++--%K%(6! &  #1 040K  %    
${{-7c*:://11"LL *>),: !   $H
$ sN   'C E
C'6E
CCAE:EEE
EE
E)rQ  rO  rP  )r	  r
  r  r  r  r+   r5   r  r  r   r  r$  r  r  r  s   @r   r   r   z  s0    .
 )(1 (1r   r   c                   Z    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rSrg)r   i  ab  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                 L    0 U l         S U l        [        R                  " SSSS9  g )Nr   r  r  r  )r  _saved_sighandlerr:   r  r)  s    r   r+   MultiLoopChildWatcher.__init__  s*    !%4;%,	.r   c                     U R                   S L$ r!   )rb  r)  s    r   r   MultiLoopChildWatcher.is_active  s    %%T11r   c                 T   U R                   R                  5         U R                  c  g [        R                  " [        R
                  5      nXR                  :w  a  [        R                  " S5        O/[        R                  " [        R
                  U R                  5        S U l        g )Nz+SIGCHLD handler was changed by outside code)	r  r=   rb  rO   	getsignalr)  r*  r   r  )r.   rl   s     r   r5   MultiLoopChildWatcher.close  sl    !!)""6>>2nn$NNHIMM&..$*@*@A!%r   c                     U $ r!   r   r)  s    r   r  MultiLoopChildWatcher.__enter__  r  r   c                     g r!   r   r.   r  exc_valexc_tbs       r   r  MultiLoopChildWatcher.__exit__  r  r   c                 r    [         R                  " 5       nXBU4U R                  U'   U R                  U5        g r!   )r   r  r  r   )r.   r   r[   r\   r"  s        r   r   'MultiLoopChildWatcher.add_child_handler  s3    &&( $5 	r   c                 @     U R                   U	 g! [         a     gf = fr<  r=  r  s     r   r  *MultiLoopChildWatcher.remove_child_handler  r?  r@  c                 B   U R                   b  g [        R                  " [        R                  U R                  5      U l         U R                   c+  [        R
                  " S5        [        R                  U l         [        R                  " [        R                  S5        g )NzaPrevious SIGCHLD handler was set by non-Python code, restore to default handler on watcher close.F)rb  rO   r)  r*  r   r  rk   rW   r  s     r   r  !MultiLoopChildWatcher.attach_loop%  so    
 !!-!'v~~t~~!N!!)NN J K%+^^D" 	FNNE2r   c                 ^    [        U R                  5       H  nU R                  U5        M     g r!   rB  r  s     r   r$  %MultiLoopChildWatcher._do_waitpid_all6  s#    (CS! )r   c                 X   US:  d   e [         R                  " U[         R                  5      u  p#US:X  a  g [        U5      nSn U R                  R                  U5      u  pgnUR                  5       (       a  [
        R                  " SXb5        g U(       a,  UR                  5       (       a  [
        R                  " SX5        UR                  " XrU/UQ76   g ! [         a     UnSn[
        R                  " SU5        Sn Nf = f! [         a    [
        R                  " SUSS	9   g f = f)
Nr   Tr  rF  F%Loop %r that handles pid %r is closedrE  rG  rl  )r"   r  rH  r#   r  r   r  r  rI  	is_closedrC  rJ  r   rh   )	r.   r  r   r%   r   	debug_logr"  r[   r\   s	            r   r   !MultiLoopChildWatcher._do_waitpid:  s   a	**\2::>KC ax/7JI	L#'??#6#6s#; DD ~~FR!1!1LL!G!-;))(KdK= ! 	 CJNNJ I	$  	/ NND/	/s#   'C D 'DD D)(D)c                      U R                  5         g ! [        [        4 a    e [         a    [        R
                  " SSS9   g f = f)Nr-  Trl  )r$  r   r   r   r   r  )r.   r   r   s      r   r*  MultiLoopChildWatcher._sig_chld_  sE    	R  "-. 	 	RNNADQ	Rs    /AA)r  rb  N)r	  r
  r  r  r  r+   r   r5   r  r  r   r  r  r$  r   r*  r  r   r   r   r   r     sA    	$.2
&3""#LJRr   r   c                   n    \ rS rSrSrS rS rS rS rS r	\
R                  4S jrS	 rS
 rS rS rSrg)r   ih  a%  Threaded 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                 H    [         R                  " S5      U l        0 U l        g r   )	itertoolsr   _pid_counter_threadsr)  s    r   r+   ThreadedChildWatcher.__init__u  s    %OOA.r   c                     gru  r   r)  s    r   r   ThreadedChildWatcher.is_activey  r  r   c                     g r!   r   r)  s    r   r5   ThreadedChildWatcher.close|  r  r   c                     U $ r!   r   r)  s    r   r  ThreadedChildWatcher.__enter__  r  r   c                     g r!   r   rl  s       r   r  ThreadedChildWatcher.__exit__  r  r   c                     [        U R                  R                  5       5       Vs/ s H  nUR                  5       (       d  M  UPM     nnU(       a  U" U R                   S3[
        U S9  g g s  snf )Nz0 has registered but not finished child processesr3   )r8   r  valuesis_aliver0   r<   )r.   rf  threadthreadss       r   rg  ThreadedChildWatcher.__del__  se    (,T]]-A-A-C(D )(Dfoo' (D )T^^$$TU! )s   A-A-c                     [         R                  " 5       n[        R                  " U R                  S[        U R                  5       3XAX#4SS9nXPR                  U'   UR                  5         g )Nzasyncio-waitpid-T)targetnamer\   daemon)	r   r  rM  Threadr   nextr  r  start)r.   r   r[   r\   r"  r  s         r   r   &ThreadedChildWatcher.add_child_handler  s`    &&(!!)9)9)9$t?P?P:Q9R'S(,8'B)-/ $cr   c                     gru  r   r  s     r   r  )ThreadedChildWatcher.remove_child_handler  r  r   c                     g r!   r   r  s     r   r   ThreadedChildWatcher.attach_loop  r  r   c                    US:  d   e [         R                  " US5      u  pV[        U5      nUR                  5       (       a  [        R
                  " SX'5        UR                  5       (       a  [        R                  " SX5        OUR                  " X5U/UQ76   U R                  R                  U5        g ! [         a    UnSn[        R                  " SU5         Nf = f)Nr   rE  r  rF  ry  )r"   r  r#   rC  r   rJ  r  r  rz  r   r  rI  )r.   r"  r  r[   r\   r   r%   r   s           r   r    ThreadedChildWatcher._do_waitpid  s    a	7**\15KC 07J~~C)7 >>NNBDN%%hZG$G,'' ! 	 CJNNJ	s   B7 7%CC)r  r  N)r	  r
  r  r  r  r+   r   r5   r  r  r:   r;   rg  r   r  r  r   r  r   r   r   r   r   h  sB    
 %MM (r   r   c                      [        [        S5      (       d  g [        R                  " 5       n [        R                  " [        R                  " U S5      5        g! [
         a     gf = f)Nr  Fr   T)hasattrr"   getpidr5   r  rS   )r   s    r   can_use_pidfdr    sR    2|$$iik
sA&'   s   A A 
A&%A&c                   N   ^  \ rS rSrSr\rU 4S jrS rU 4S jr	S r
S rSrU =r$ )	_UnixDefaultEventLoopPolicyi  z:UNIX event loop policy with a watcher for child processes.c                 0   > [         TU ]  5         S U l        g r!   )r*   r+   _watcherr1  s    r   r+   $_UnixDefaultEventLoopPolicy.__init__  s    r   c                     [         R                     U R                  c.  [        5       (       a  [	        5       U l        O[        5       U l        S S S 5        g ! , (       d  f       g = fr!   )r   rO  r  r  r   r   r)  s    r   _init_watcher)_UnixDefaultEventLoopPolicy._init_watcher  s8    \\}}$ ??$5$7DM$8$:DM \\s   <A
A$c                    > [         TU ]  U5        U R                  bH  [        R                  " 5       [        R
                  " 5       L a  U R                  R                  U5        ggg)zSet 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  rM  current_threadmain_threadr  )r.   r"  r0   s     r   r  *_UnixDefaultEventLoopPolicy.set_event_loop  sS     	t$MM%((*i.C.C.EEMM%%d+ F &r   c                     U R                   c  U R                  5         [        R                  " SSSS9  U R                   $ )znGet the watcher for child processes.

If not yet set, a ThreadedChildWatcher object is automatically created.
r   r  r  r  )r  r  r:   r  r)  s    r   r   -_UnixDefaultEventLoopPolicy.get_child_watcher  s@    
 ==  0:BI	K }}r   c                     Ub  [        U[        5      (       d   eU R                  b  U R                  R                  5         Xl        [        R
                  " SSSS9  g)z$Set the watcher for child processes.Nset_child_watcherr  r  r  )ro   r   r  r5   r:   r  )r.   r   s     r   r  -_UnixDefaultEventLoopPolicy.set_child_watcher  sU     *W6J"K"KKK==$MM!0:BI	Kr   )r  )r	  r
  r  r  r  r'   _loop_factoryr+   r  r  r   r  r  r  r  s   @r   r  r    s+    D*M;,K Kr   r  )5r  rY   r   r  r"   r8  rO   r   r   r  r6   rM  r:    r   r   r   r   r   r	   r
   r   r   r   logr   __all__r  ImportErrorr   r#   BaseSelectorEventLoopr'   ReadTransportrt   _FlowControlMixinWriteTransportr}   BaseSubprocessTransportr   r   r   r  r   r   r   r   r  BaseDefaultEventLoopPolicyr  r   r   r   r   r   r   <module>r     sj   8  	  	      
              <<7
C
DD	
r2_BB r2jMZ55 M`Jj::(77JZ FF  0S$ S$l7, 7t2+ 2jN-' N-bj1' j1Z~R0 ~RBO(/ O(b	6K&"C"C 6Kr + 4 	r   