
    Rh                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ dZe
j6                  dk(  r ed      d Zd Z G d dej>                        Z  G d dejB                        Z" G d dejF                  ejH                        Z% G d dejL                        Z' G d d      Z( G d de(      Z) G d  d!e(      Z* G d" d#e*      Z+ G d$ d%e*      Z, G d& d'e(      Z- G d( d)e(      Z.d* Z/ G d+ d,ej`                        Z1e Z2e1Z3y)-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                      y)zDummy signal handler.N )signumframes     */usr/lib/python3.12/asyncio/unix_events.py_sighandler_noopr   *   s        c                 P    	 t        j                  |       S # t        $ r | cY S w xY wN)oswaitstatus_to_exitcode
ValueError)statuss    r   r"   r"   /   s.    ((00  	s    %%c                        e Zd ZdZd fd	Z fdZd Zd Zd Zd Z	d	 Z
	 	 dd
Z	 	 ddZ	 ddZd Z	 ddddddddZ	 dddddddddZd Zd Zd Zd Z xZS )_UnixSelectorEventLoopzdUnix event loop.

    Adds signal handling and UNIX Domain Socket support to SelectorEventLoop.
    Nc                 2    t         |   |       i | _        y r    )super__init___signal_handlers)selfselector	__class__s     r   r)   z_UnixSelectorEventLoop.__init__?   s    " "r   c                 0   t         |           t        j                         s,t	        | j
                        D ]  }| j                  |        y | j
                  r;t        j                  d| dt        |        | j
                  j                          y y )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+   sigr-   s     r   r1   z_UnixSelectorEventLoop.closeC   s      "D112 0**3/0 $$ 1$ :H I .%)	+
 %%++- %r   c                 :    |D ]  }|s| j                  |        y r    )_handle_signal)r+   datar   s      r   _process_self_dataz)_UnixSelectorEventLoop._process_self_dataQ   s%     	(F'		(r   c                 R   t        j                  |      st        j                  |      rt        d      | j	                  |       | j                          	 t        j                  | j                  j                                t        j                  ||| d      }|| j                   |<   	 t        j                  |t"               t        j$                  |d       y# t        t        f$ r}t        t        |            d}~ww xY w# t        $ r}| j                   |= | j                   sI	 t        j                  d       n2# t        t        f$ r }t'        j(                  d|       Y d}~nd}~ww xY w|j*                  t*        j,                  k(  rt        d| d       d}~ww xY w)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_handlerz)_UnixSelectorEventLoop.add_signal_handlerX   sq    ""8,..x8 8 9 93	)
   !3!3!56 xtT:%+c"	 MM#/0 U+ G$ 	)s3x((	)  	%%c*((F((,"G, FKK >EEF yyELL("T#.?#@AA	sZ   -C -0D	 D-DD		F&F!,EF!E1E,'F!,E110F!!F&c                     | j                   j                  |      }|y|j                  r| j                  |       y| j	                  |       y)z2Internal helper that is the actual signal handler.N)r*   get
_cancelledr5   _add_callback_signalsafe)r+   r:   rX   s      r   r<   z%_UnixSelectorEventLoop._handle_signal   sE    &&**3/>&&s+))&1r   c                    | j                  |       	 | j                  |= |t        j                  k(  rt        j
                  }nt        j                  }	 t        j                  ||       | j                  s	 t        j                  d       yy# t        $ r Y yw xY w# t        $ r2}|j                  t        j                  k(  rt        d| d       d}~ww xY w# t        t        f$ r }t        j                  d|       Y d}~yd}~ww xY w)zwRemove a handler for a signal.  UNIX only.

        Return True if a signal handler was removed, False if not.
        FrB   rC   Nr@   rA   T)rG   r*   KeyErrorrI   SIGINTdefault_int_handlerSIG_DFLrM   rS   rT   rN   rJ   r#   r   rR   )r+   r:   handlerrW   s       r   r5   z,_UnixSelectorEventLoop.remove_signal_handler   s    
 	3	%%c* &--00GnnG	MM#w' $$A$$R( -  		  	yyELL("T#.?#@AA		 ( A:C@@AsA   B B 8C 	BB	C'-CCD+DDc                     t        |t              st        d|      |t        j                         vrt        d|       y)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intrF   rI   valid_signalsr#   )r+   r:   s     r   rG   z$_UnixSelectorEventLoop._check_signal   sJ     #s#6sg>??f**,,5cU;<< -r   c                      t        | ||||      S r    )_UnixReadPipeTransportr+   pipeprotocolwaiterextras        r   _make_read_pipe_transportz0_UnixSelectorEventLoop._make_read_pipe_transport   s    %dD(FEJJr   c                      t        | ||||      S r    )_UnixWritePipeTransportrk   s        r   _make_write_pipe_transportz1_UnixSelectorEventLoop._make_write_pipe_transport   s    &tT8VUKKr   c	                 l  K   t        j                         5  t        j                  dt               t	        j
                         }
d d d        
5  |
j                         st        d      | j                         }t        | |||||||f||d|	}|
j                  |j                         | j                  |       	 | d {    	 d d d        |S # 1 sw Y   xY w7 # t        t        f$ r  t        $ r+ |j!                          |j#                          d {  7    w xY w# 1 sw Y   S xY ww)NignorezRasyncio.get_child_watcher() is not activated, subprocess support is not installed.)rn   ro   )r6   catch_warningssimplefilterDeprecationWarningr   get_child_watcher	is_activerN   create_future_UnixSubprocessTransportadd_child_handlerget_pid_child_watcher_callback
SystemExitKeyboardInterruptBaseExceptionr1   _wait)r+   rm   rV   shellstdinstdoutstderrbufsizero   kwargswatcherrn   transps                r   _make_subprocess_transportz1_UnixSelectorEventLoop._make_subprocess_transport   s;     $$& 	1!!(,>?..0G	1  	$$&
 # $G H H'')F-dHdE,16676396 /56F %%fnn&6$($@$@&J!	0 9	1 	1(  12   lln$$'	0 se   D4/C
D4A-D'>C!CC!	
D4CD4C!!;D$DD$$D''D1,D4c                 <    | j                  |j                  |       y r    )call_soon_threadsafe_process_exited)r+   pid
returncoder   s       r   r   z._UnixSelectorEventLoop._child_watcher_callback   s    !!&"8"8*Er   )sslsockserver_hostnamessl_handshake_timeoutssl_shutdown_timeoutc                  K   |t        |t              sJ |r|2t        d      |t        d      |t        d      |t        d      ||t        d      t        j                  |      }t        j
                  t
        j                  t
        j                  d      }	 |j                  d       | j                  ||       d {    nf|t        d      |j                  t
        j                  k7  s|j                  t
        j                  k7  rt        d	|      |j                  d       | j                  ||||||
       d {   \  }}	||	fS 7 #  |j                           xY w7 #w)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   )rf   rO   r#   r!   fspathsocketAF_UNIXSOCK_STREAMsetblockingsock_connectr1   familytype_create_connection_transport)
r+   protocol_factorypathr   r   r   r   r   	transportrm   s
             r   create_unix_connectionz-_UnixSelectorEventLoop.create_unix_connection   s     &*_c*JJJ& EG G * !NOO$0 GI I#/ FH H  IK K 99T?D==1C1CQGD  '''d333 | !BCCv~~-II!3!33 DTHMO OU#$($E$E"C"7!5 %F %7 7	8 (""% 4

7s=   B"E7%&E EE BE7E5E7E E22E7d   T)r   backlogr   r   r   start_servingc          	        K   t        |t              rt        d      ||st        d      ||st        d      ||t        d      t	        j
                  |      }t        j                  t        j                  t        j                        }|d   dvrH	 t        j                  t	        j                  |      j                        rt	        j                  |       	 |j#                  |       nU|t        d
      |j*                  t        j                  k7  s|j,                  t        j                  k7  rt        d|      |j/                  d       t1        j2                  | |g|||||      }|r-|j5                          t7        j8                  d       d {    |S # t        $ r Y t        $ r!}	t        j                   d||	       Y d }	~	d }	~	ww xY w# t        $ rT}
|j%                          |
j&                  t&        j(                  k(  r!d|d	}t        t&        j(                  |      d  d }
~
w |j%                           xY w7 w)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)rf   boolrF   r#   r!   r   r   r   r   statS_ISSOCKst_moderemoveFileNotFoundErrorrM   r   errorbindr1   rS   
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_server  s7     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 	##D4&2B$'2G$8: !!# ++a.  S )  6LL "*+/6 66  

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

& !si   BIAF' "G 3B-I I!I'	G0I2G:GIGI	I'AH66IIc           
        K   	 t         j                   	 |j                         }	 t        j                  |      j                  }|r|n|}|sy| j                         }	| j                  |	d |||||d       |	 d {   S # t        $ r t        j                  d      w xY w# t        t        j                  f$ r}t        j                  d      d }~ww xY w# t        $ r t        j                  d      w xY w7 ~w)Nzos.sendfile() is not availableznot a regular filer   )r!   sendfileAttributeErrorr	   SendfileNotAvailableErrorrL   ioUnsupportedOperationfstatst_sizerM   r{   _sock_sendfile_native_impl)
r+   r   fileoffsetcountrL   r   fsize	blocksizefuts
             r   _sock_sendfile_nativez,_UnixSelectorEventLoop._sock_sendfile_nativeb  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   C<B  B" C 6C<;C:<C< BC<"C;CCC<C77C<c	                    |j                         }	|| j                  |       |j                         r| j                  |||       y |r/||z
  }|dk  r%| j                  |||       |j	                  |       y 	 t        j                  |	|||      }
|
dk(  r%| j                  |||       |j	                  |       y ||
z  }||
z  }|| j                  ||       | j                  |	| j                  ||	||||||
       y # t        t        f$ r; || j                  ||       | j                  |	| j                  ||	||||||
       Y y t        $ r}|Q|j                  t        j                  k(  r4t        |      t         ur#t!        dt        j                        }||_        |}|dk(  r:t%        j&                  d      }| j                  |||       |j)                  |       n)| j                  |||       |j)                  |       Y d }~y Y d }~y d }~wt*        t,        f$ r  t.        $ r.}| j                  |||       |j)                  |       Y d }~y d }~ww xY w)Nr   zsocket is not connectedzos.sendfile call failed)rL   remove_writer	cancelled_sock_sendfile_update_filepos
set_resultr!   r   _sock_add_cancellation_callback
add_writerr   BlockingIOErrorInterruptedErrorrM   rS   ENOTCONNr   ConnectionError	__cause__r	   r   set_exceptionr   r   r   )r+   r   registered_fdr   rL   r   r   r   
total_sentfdsentrW   new_excr   s                 r   r   z1_UnixSelectorEventLoop._sock_sendfile_native_imply  sT   [[]$
 }-==?..vvzJ
*IA~2266:Nz*1	F;;r669=DJ qy2266:Nz*$d"
 (88dCD$C$CS "D& &y*F[  !12 	B$44S$?OOB ? ?f"E9jB  	')II/I_4
 *-u~~?$'!Q
 !::-/2266:N!!#&2266:N!!#&& ' -. 	 	#..vvzJc""	#s,   :C? ?AIIB6HI+$IIc                 Z    |dkD  r&t        j                  ||t         j                         y y Nr   )r!   lseekSEEK_SET)r+   rL   r   r   s       r   r   z4_UnixSelectorEventLoop._sock_sendfile_update_filepos  s"    >HHVVR[[1 r   c                 6      fd}|j                  |       y )Nc                 v    | j                         r(j                         }|dk7  rj                  |       y y y )Nr@   )r   rL   r   )r   r   r+   r   s     r   cbzB_UnixSelectorEventLoop._sock_add_cancellation_callback.<locals>.cb  s6    }}[[]8&&r*  r   )add_done_callback)r+   r   r   r   s   ` ` r   r   z6_UnixSelectorEventLoop._sock_add_cancellation_callback  s    	+
 	b!r   r    NN)__name__
__module____qualname____doc__r)   r1   r>   rZ   r<   r5   rG   rp   rs   r   r   r   r   r   r   r   r   __classcell__r-   s   @r   r&   r&   9   s    
#.(+Z2@
= @D(,K AE)-L 04BF *.0#4 "&!%0#f *.Gs"&!%GR.DFL2"r   r&   c                        e Zd ZdZd fd	Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   fdZddZd Zd Z xZS )rj   i   c                 4   t         |   |       || j                  d<   || _        || _        |j                         | _        || _        d| _        d| _	        t        j                  | j                        j                  }t        j                  |      sJt        j                  |      s5t        j                   |      s d | _        d | _        d | _        t#        d      t        j$                  | j                  d       | j                  j'                  | j                  j(                  |        | j                  j'                  | j*                  | j                  | j,                         |,| j                  j'                  t.        j0                  |d        y y )Nrl   Fz)Pipe transport is for pipes/sockets only.)r(   r)   _extra_loop_piperL   _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+   looprl   rm   rn   ro   moder-   s          r   r)   z_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                 ^    | j                         sy | j                  j                  ||       y r    )
is_readingr   r   )r+   r   rU   s      r   r   z"_UnixReadPipeTransport._add_reader  s#     

r8,r   c                 :    | j                    xr | j                   S r    )r   r   r+   s    r   r  z!_UnixReadPipeTransport.is_reading  s    <<5$55r   c                 t   | j                   j                  g}| j                  |j                  d       n| j                  r|j                  d       |j                  d| j
                          t        | j                  dd       }| j                  W|Ut        j                  || j
                  t        j                        }|r|j                  d       nA|j                  d       n/| j                  |j                  d       n|j                  d       dj                  d	j                  |            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+   rR   r,   r  s       r   __repr__z_UnixReadPipeTransport.__repr__  s    ''(::KK!]]KK	"c$,,()4::{D9::!h&:%::$,,	(<(<>GI&F#ZZ#KKKK!}}SXXd^,,r   c                 h   	 t        j                  | j                  | j                        }|r| j                  j                  |       y | j                  j                         rt        j                  d|        d| _
        | j                  j                  | j                         | j                  j                  | j                  j                         | j                  j                  | j                  d        y # t        t         f$ r Y y t"        $ r}| j%                  |d       Y d }~y d }~ww xY w)N%r was closed by peerTz"Fatal read error on pipe transport)r!   readr   max_sizer   data_receivedr   	get_debugr   rR   r   _remove_readerr   eof_received_call_connection_lostr   r   rM   _fatal_error)r+   r=   rW   s      r   r   z"_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   *C< <D1D1D,,D1c                     | j                         sy d| _        | j                  j                  | j                         | j                  j                         rt        j                  d|        y y )NTz%r pauses reading)r  r   r   r  r   r  r   debugr  s    r   pause_readingz$_UnixReadPipeTransport.pause_reading  sP     

!!$,,/::!LL,d3 "r   c                    | j                   s| j                  sy d| _        | j                  j                  | j                  | j
                         | j                  j                         rt        j                  d|        y y )NFz%r resumes reading)	r   r   r   r   r   r   r  r   r#  r  s    r   resume_readingz%_UnixReadPipeTransport.resume_reading%  s[    ==

t||T-=-=>::!LL-t4 "r   c                     || _         y r    r   r+   rm   s     r   set_protocolz#_UnixReadPipeTransport.set_protocol-  	    !r   c                     | j                   S r    r(  r  s    r   get_protocolz#_UnixReadPipeTransport.get_protocol0      ~~r   c                     | j                   S r    r   r  s    r   
is_closingz!_UnixReadPipeTransport.is_closing3      }}r   c                 @    | j                   s| j                  d        y y r    )r   _closer  s    r   r1   z_UnixReadPipeTransport.close6  s    }}KK r   c                 v    | j                   - |d| t        |        | j                   j                          y y Nzunclosed transport r/   r   r8   r1   r+   _warns     r   __del__z_UnixReadPipeTransport.__del__:  5    ::!'x0/$OJJ "r   c                 <   t        |t              rQ|j                  t        j                  k(  r4| j                  j                         rDt        j                  d| |d       n*| j                  j                  ||| | j                  d       | j                  |       y Nz%r: %sTexc_info)message	exceptionr   rm   )rf   rM   rS   EIOr   r  r   r#  call_exception_handlerr   r4  r+   rW   r@  s      r   r!  z#_UnixReadPipeTransport._fatal_error?  sr    sG$eii)?zz##%XtWtDJJ--" ! NN	/  	Cr   c                     d| _         | j                  j                  | j                         | j                  j	                  | j
                  |       y NT)r   r   r  r   r   r   r+   rW   s     r   r4  z_UnixReadPipeTransport._closeM  s9    

!!$,,/

T77=r   c                    	 | j                   j                  |       | j                  j                          d | _        d | _         d | _        y # | j                  j                          d | _        d | _         d | _        w xY wr    r   connection_lostr   r1   r   rG  s     r   r   z,_UnixReadPipeTransport._call_connection_lostR  g    	NN**3/JJDJ!DNDJ JJDJ!DNDJ   A 1A>r   zFatal error on pipe transport)r   r   r   r  r)   r   r  r  r   r$  r&  r*  r-  r1  r1   r6   r7   r:  r!  r4  r   r   r   s   @r   rj   rj     s]    H/<-
6-*G$45" %MM 
>
r   rj   c                        e Zd Zd fd	Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zej                   fdZd ZddZddZd Z xZS )rr   c                    t         
|   ||       || j                  d<   || _        |j	                         | _        || _        t               | _        d| _	        d| _
        t        j                  | j
                        j                  }t        j                  |      }t        j                   |      }t        j"                  |      }	|s$|s"|	s d | _        d | _        d | _        t%        d      t        j&                  | j
                  d       | j(                  j+                  | j                  j,                  |        |	s!|rdt.        j0                  j3                  d      sE| j(                  j+                  | j(                  j4                  | j
                  | j6                         |,| j(                  j+                  t8        j:                  |d        y y )Nrl   r   Fz?Pipe transport is only for pipes, sockets and character devicesaix)r(   r)   r   r   rL   r   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   rl   rm   rn   ro   r  is_charis_fifo	is_socketr-   s             r   r)   z _UnixWritePipeTransport.__init___  si   %"F
{{}! {xx%--,,t$--%MM$'	7iDJDL!DN D E E 	e,

T^^;;TB
 )@)@)GJJ  !7!7!%t/?/?A JJ  !E!E!'/ r   c                    | j                   j                  g}| j                  |j                  d       n| j                  r|j                  d       |j                  d| j
                          t        | j                  dd       }| j                  {|yt        j                  || j
                  t        j                        }|r|j                  d       n|j                  d       | j                         }|j                  d|        n/| j                  |j                  d       n|j                  d       d	j                  d
j                  |            S )Nr  r  r	  r
  r  r  zbufsize=r  r  r  )r-   r   r   r  r   r   r  r   r   r  r  EVENT_WRITEget_write_buffer_sizer  r  )r+   rR   r,   r  r   s        r   r  z _UnixWritePipeTransport.__repr__  s   ''(::KK!]]KK	"c$,,()4::{D9::!h&:%::$,,	(=(=?GI&F#002GKK(7),-ZZ#KKKK!}}SXXd^,,r   c                 ,    t        | j                        S r    )lenrR  r  s    r   r[  z-_UnixWritePipeTransport.get_write_buffer_size  s    4<<  r   c                     | j                   j                         rt        j                  d|        | j                  r| j                  t                      y | j                          y )Nr  )r   r  r   rR   rR  r4  BrokenPipeErrorr  s    r   r   z#_UnixWritePipeTransport._read_ready  s@    ::!KK/6<<KK)*KKMr   c                 Z   t        |t        t        t        f      sJ t	        |             t        |t              rt        |      }|sy | j
                  s| j                  rH| j
                  t        j                  k\  rt        j                  d       | xj
                  dz  c_        y | j                  ss	 t        j                  | j                  |      }|t+        |      k(  ry |dkD  rt        |      |d  }| j,                  j/                  | j                  | j0                         | xj                  |z  c_        | j3                          y # t        t         f$ r d}Y t"        t$        f$ r  t&        $ r1}| xj
                  dz  c_        | j)                  |d       Y d }~y d }~ww xY w)Nz=pipe closed by peer or os.write(pipe, data) raised exception.r   r   #Fatal write error on pipe transport)rf   bytesrQ  
memoryviewreprrS  r   r   !LOG_THRESHOLD_FOR_CONNLOST_WRITESr   warningrR  r!   writer   r   r   r   r   r   r!  r]  r   _add_writer_write_ready_maybe_pause_protocol)r+   r=   nrW   s       r   rg  z_UnixWritePipeTransport.write  sW   $	: >?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   7 E F*"F*9'F%%F*c                 4   | j                   sJ d       	 t        j                  | j                  | j                         }|t	        | j                         k(  r| j                   j                          | j                  j                  | j                         | j                          | j                  r6| j                  j                  | j                         | j                  d        y |dkD  r| j                   d |= y y # t        t        f$ r Y y t        t        f$ r  t         $ rp}| j                   j                          | xj"                  dz  c_        | j                  j                  | j                         | j%                  |d       Y d }~y d }~ww xY w)NzData should not be emptyr   r   ra  )rR  r!   rg  r   r]  r9   r   _remove_writer_maybe_resume_protocolr   r  r   r   r   r   r   r   rS  r!  )r+   rk  rW   s      r   ri  z$_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   *C? ?FF'A&FFc                      yrF  r   r  s    r   can_write_eofz%_UnixWritePipeTransport.can_write_eof      r   c                     | j                   ry | j                  sJ d| _         | j                  sL| j                  j	                  | j
                         | j                  j                  | j                  d        y y rF  )r   r   rR  r   r  r   r   r   r  s    r   	write_eofz!_UnixWritePipeTransport.write_eof  s[    ==zzz||JJ%%dll3JJ  !;!;TB r   c                     || _         y r    r(  r)  s     r   r*  z$_UnixWritePipeTransport.set_protocol  r+  r   c                     | j                   S r    r(  r  s    r   r-  z$_UnixWritePipeTransport.get_protocol  r.  r   c                     | j                   S r    r0  r  s    r   r1  z"_UnixWritePipeTransport.is_closing  r2  r   c                 X    | j                   | j                  s| j                          y y y r    )r   r   rs  r  s    r   r1   z_UnixWritePipeTransport.close  s$    ::!$--NN +8!r   c                 v    | j                   - |d| t        |        | j                   j                          y y r6  r7  r8  s     r   r:  z_UnixWritePipeTransport.__del__  r;  r   c                 &    | j                  d        y r    )r4  r  s    r   abortz_UnixWritePipeTransport.abort  s    Dr   c                    t        |t              r4| j                  j                         rDt	        j
                  d| |d       n*| j                  j                  ||| | j                  d       | j                  |       y r=  )	rf   rM   r   r  r   r#  rC  r   r4  rD  s      r   r!  z$_UnixWritePipeTransport._fatal_error	  sc    c7#zz##%XtWtDJJ--" ! NN	/  	Cr   c                 >   d| _         | j                  r%| j                  j                  | j                         | j                  j                          | j                  j                  | j                         | j                  j                  | j                  |       y rF  )	r   rR  r   rm  r   r9   r  r   r   rG  s     r   r4  z_UnixWritePipeTransport._close  sf    <<JJ%%dll3

!!$,,/

T77=r   c                    	 | j                   j                  |       | j                  j                          d | _        d | _         d | _        y # | j                  j                          d | _        d | _         d | _        w xY wr    rI  rG  s     r   r   z-_UnixWritePipeTransport._call_connection_lost  rK  rL  r   rM  r    )r   r   r   r)   r  r[  r   rg  ri  rp  rs  r*  r-  r1  r1   r6   r7   r:  rz  r!  r4  r   r   r   s   @r   rr   rr   \  sd    #/J-0!!%F%8C"
 %MM 
>r   rr   c                       e Zd Zd Zy)r|   c           
         d }|t         j                  k(  r6t        j                  j	                  d      rt        j                         \  }}	 t        j                  |f||||d|d|| _        |=|j                          t        |j                         d|      | j                  _        d }|!|j                          |j                          y y # |!|j                          |j                          w w xY w)NrP  F)r   r   r   r   universal_newlinesr   wb)	buffering)
subprocessPIPEr2   rT  rU  r   
socketpairPopen_procr1   r  detachr   )	r+   rV   r   r   r   r   r   r   stdin_ws	            r   _startz_UnixSubprocessTransport._start+  s    JOO#(?(?(F
 $..0NE7	 #))E!vf#('E=CEDJ "#'(8$'#R

 " #w" #s   A!C %C7N)r   r   r   r  r   r   r   r|   r|   )  s     r   r|   c                   B    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zy)r   aH  Abstract base class for monitoring child processes.

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

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

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

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

        Since child watcher objects may catch the SIGCHLD signal and call
        waitpid(-1), there should be only one active object per process.
    Nc                 \    | j                   t        k7  rt        j                  ddd       y y )Nr   P{name!r} is deprecated as of Python 3.12 and will be removed in Python {remove}.      r   )r   r   r6   _deprecated)clss    r   __init_subclass__z&AbstractChildWatcher.__init_subclass__X  s,    >>X%  !7;%,. &r   c                     t               )a  Register a new child handler.

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

        Note: callback() must be thread-safe.
        NotImplementedErrorr+   r   rU   rV   s       r   r}   z&AbstractChildWatcher.add_child_handler_  s     "##r   c                     t               )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_handlerz)AbstractChildWatcher.remove_child_handlerj  s     "##r   c                     t               )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_loopz AbstractChildWatcher.attach_loopr  s     "##r   c                     t               )zlClose the watcher.

        This must be called to make sure that any underlying resource is freed.
        r  r  s    r   r1   zAbstractChildWatcher.close|  s    
 "##r   c                     t               )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   rz   zAbstractChildWatcher.is_active  s     "##r   c                     t               )zdEnter the watcher's context and allow starting new processes

        This function must return selfr  r  s    r   	__enter__zAbstractChildWatcher.__enter__  s     "##r   c                     t               )zExit the watcher's contextr  r+   abcs       r   __exit__zAbstractChildWatcher.__exit__  s    !##r   )returnN)r   r   r   r   r  r}   r  r  r1   rz   r  r  r   r   r   r   r   A  s/    ,.	$$$$$$$r   r   c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)r   a6  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                     | S r    r   r  s    r   r  zPidfdChildWatcher.__enter__      r   c                      y r    r   )r+   exc_type	exc_valueexc_tracebacks       r   r  zPidfdChildWatcher.__exit__      r   c                      yrF  r   r  s    r   rz   zPidfdChildWatcher.is_active  rq  r   c                      y r    r   r  s    r   r1   zPidfdChildWatcher.close  r  r   c                      y r    r   r  s     r   r  zPidfdChildWatcher.attach_loop  r  r   c                     t        j                         }t        j                  |      }|j	                  || j
                  ||||       y r    )r   get_running_loopr!   
pidfd_openr   _do_wait)r+   r   rU   rV   r   pidfds         r   r}   z#PidfdChildWatcher.add_child_handler  s:    &&(c"sE8TJr   c                 $   t        j                         }|j                  |       	 t        j                  |d      \  }}t        |      }t        j                  |        |||g|  y # t        $ r d}t        j                  d|       Y Cw xY w)Nr      zJchild process pid %d exit status already read:  will report returncode 255)
r   r  r  r!   waitpidr"   ChildProcessErrorr   rf  r1   )	r+   r   r  rU   rV   r   _r$   r   s	            r   r  zPidfdChildWatcher._do_wait  s    &&(E"	8

3*IAv 07J
j(4( ! 	 JNN.		s   A+ +!BBc                      yrF  r   r  s     r   r  z&PidfdChildWatcher.remove_child_handler       r   N)r   r   r   r   r  r  rz   r1   r  r}   r  r  r   r   r   r   r     s0    	K
)&r   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	BaseChildWatcherc                      d | _         i | _        y r    )r   
_callbacksr  s    r   r)   zBaseChildWatcher.__init__  s    
r   c                 &    | j                  d        y r    )r  r  s    r   r1   zBaseChildWatcher.close  s    r   c                 V    | j                   d uxr | j                   j                         S r    )r   
is_runningr  s    r   rz   zBaseChildWatcher.is_active  s#    zz%A$***?*?*AAr   c                     t               r    r  )r+   expected_pids     r   _do_waitpidzBaseChildWatcher._do_waitpid      !##r   c                     t               r    r  r  s    r   _do_waitpid_allz BaseChildWatcher._do_waitpid_all  r  r   c                    |t        |t        j                        sJ | j                  (|&| j                  rt        j                  dt               | j                  )| j                  j                  t        j                         || _        |;|j                  t        j                  | j                         | j                          y y )NzCA loop is being detached from a child watcher with pending handlers)rf   r   AbstractEventLoopr   r  r6   r7   RuntimeWarningr5   rI   SIGCHLDrZ   	_sig_chldr  r  s     r   r  zBaseChildWatcher.attach_loop  s    |z$0H0HIII::!dltMM= 
 ::!JJ,,V^^<
##FNNDNNC   " r   c                     	 | j                          y # t        t        f$ r  t        $ r(}| j                  j                  d|d       Y d }~y d }~ww xY w)N$Unknown exception in SIGCHLD handler)r@  rA  )r  r   r   r   r   rC  rG  s     r   r  zBaseChildWatcher._sig_chld  sX    	  "-. 	 	 JJ--A /  		s    AAAN)
r   r   r   r)   r1   rz   r  r  r  r  r   r   r   r  r    s&    B$$#(r   r  c                   P     e Zd ZdZ fdZ fdZd Zd Zd Zd Z	d Z
d	 Z xZS )
r   ad  'Safe' child watcher implementation.

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

    This is a safe solution but it has a significant overhead when handling a
    big number of children (O(n) each time SIGCHLD is raised)
    c                 R    t         |           t        j                  ddd       y )Nr   r  r  r  )r(   r)   r6   r  r+   r-   s    r   r)   zSafeChildWatcher.__init__  s'    /;%,	.r   c                 V    | j                   j                          t        |           y r    )r  r9   r(   r1   r  s    r   r1   zSafeChildWatcher.close  s    r   c                     | S r    r   r  s    r   r  zSafeChildWatcher.__enter__  r  r   c                      y r    r   r  s       r   r  zSafeChildWatcher.__exit__  r  r   c                 H    ||f| j                   |<   | j                  |       y r    )r  r  r  s       r   r}   z"SafeChildWatcher.add_child_handler"  s%     ($/ 	r   c                 >    	 | j                   |= y# t        $ r Y yw xY wNTFr  r`   r  s     r   r  z%SafeChildWatcher.remove_child_handler(  (    	$ 		    	c                 Z    t        | j                        D ]  }| j                  |        y r    r4   r  r  r  s     r   r  z SafeChildWatcher._do_waitpid_all/  s(    ( 	"CS!	"r   c                    |dkD  sJ 	 t        j                  |t         j                        \  }}|dk(  ry t        |      }| j                  j                         rt        j                  d||       	 	 | j                  j                  |      \  }} |||g|  y # t        $ r |}d}t        j                  d|       Y Ow xY w# t        $ r7 | j                  j                         rt        j                  d|d       Y y Y y w xY w)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   r  r   r#  r  rf  r  popr`   )r+   r  r   r$   r   rU   rV   s          r   r  zSafeChildWatcher._do_waitpid4  s    a	7**\2::>KC ax/7Jzz##%C):7		-!__005NHd S*,t,7 ! 	 CJNNJ	(  	3 zz##%H"T3 &	3s#   'B 4C #CC;DD)r   r   r   r   r)   r1   r  r  r}   r  r  r  r   r   s   @r   r   r     s0    ."
 -r   r   c                   J     e Zd ZdZ fdZ fdZd Zd Zd Zd Z	d Z
 xZS )	r   aW  'Fast' child watcher implementation.

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

    There is no noticeable overhead when handling a big number of children
    (O(1) each time a child terminates).
    c                     t         |           t        j                         | _        i | _        d| _        t        j                  ddd       y )Nr   r   r  r  r  )	r(   r)   	threadingLock_lock_zombies_forksr6   r  r  s    r   r)   zFastChildWatcher.__init__a  sC    ^^%
/;%,	.r   c                     | j                   j                          | j                  j                          t        |           y r    )r  r9   r  r(   r1   r  s    r   r1   zFastChildWatcher.closek  s,    r   c                 t    | j                   5  | xj                  dz  c_        | cd d d        S # 1 sw Y   y xY w)Nr   )r  r  r  s    r   r  zFastChildWatcher.__enter__p  s/    ZZ 	KK1K	 	 	s   .7c                 >   | j                   5  | xj                  dz  c_        | j                  s| j                  s
	 d d d        y t        | j                        }| j                  j	                          d d d        t        j                  d       y # 1 sw Y    xY w)Nr   z5Caught subprocesses termination from unknown pids: %s)r  r  r  rO   r9   r   rf  )r+   r  r  r  collateral_victimss        r   r  zFastChildWatcher.__exit__v  s{    ZZ 	"KK1K{{$--		" 	" "%T]]!3MM!	" 	C	 	" 	"s   /B/BBc                 
   | j                   sJ d       | j                  5  	 | j                  j                  |      }	 d d d         ||g|  y # t        $ r ||f| j
                  |<   Y d d d        y w xY w# 1 sw Y   <xY w)NzMust use the context manager)r  r  r  r  r`   r  )r+   r   rU   rV   r   s        r   r}   z"FastChildWatcher.add_child_handler  s    {{:::{ZZ 	!]]..s3
	 	j(4(  '/~$	 		 	s(   A9AA6+A95A66A99Bc                 >    	 | j                   |= y# t        $ r Y yw xY wr  r  r  s     r   r  z%FastChildWatcher.remove_child_handler  r  r  c                    	 	 t        j                  dt         j                        \  }}|dk(  ry t        |      }| j
                  5  	 | j                  j                  |      \  }}| j                  j                         rt        j                  d||       	 d d d        t        j                  d||       n
 |||g  # t        $ r Y y w xY w# t        $ r\ | j                  rK|| j                  |<   | j                  j                         rt        j                  d||       Y d d d        4d }Y w xY w# 1 sw Y   xY w)Nr@   r   r  z,unknown process %s exited with returncode %sz8Caught subprocess termination from unknown pid: %d -> %d)r!   r  r  r"   r  r  r  r  r   r  r   r#  r`   r  r  rf  )r+   r   r$   r   rU   rV   s         r   r  z FastChildWatcher._do_waitpid_all  sC    
< jjRZZ8V
 !83F;
 66%)__%8%8%=NHd zz++-%K%(*6!6&  #Z1 j040K  %    
${{-7c*:://1"LL *>),j: !6 6  $H
$6 6sN   'C D=	C'2D=	CCAD:*D=5D:7D=9D::D==E)r   r   r   r   r)   r1   r  r  r}   r  r  r   r   s   @r   r   r   W  s+    .
 )(1r   r   c                   R    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)r   a~  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                 P    i | _         d | _        t        j                  ddd       y )Nr   r  r  r  )r  _saved_sighandlerr6   r  r  s    r   r)   zMultiLoopChildWatcher.__init__  s*    !%4;%,	.r   c                     | j                   d uS r    )r  r  s    r   rz   zMultiLoopChildWatcher.is_active  s    %%T11r   c                 Z   | j                   j                          | j                  y t        j                  t        j
                        }|| j                  k7  rt        j                  d       d | _        y t        j                  t        j
                  | j                         d | _        y )Nz+SIGCHLD handler was changed by outside code)	r  r9   r  rI   	getsignalr  r  r   rf  )r+   rd   s     r   r1   zMultiLoopChildWatcher.close  sz    !!)""6>>2dnn$NNHI "& MM&..$*@*@A!%r   c                     | S r    r   r  s    r   r  zMultiLoopChildWatcher.__enter__  r  r   c                      y r    r   r+   r  exc_valexc_tbs       r   r  zMultiLoopChildWatcher.__exit__  r  r   c                 r    t        j                         }|||f| j                  |<   | j                  |       y r    )r   r  r  r  )r+   r   rU   rV   r   s        r   r}   z'MultiLoopChildWatcher.add_child_handler  s5    &&( $h5 	r   c                 >    	 | j                   |= y# t        $ r Y yw xY wr  r  r  s     r   r  z*MultiLoopChildWatcher.remove_child_handler  r  r  c                 8   | j                   y t        j                  t        j                  | j                        | _         | j                   *t	        j
                  d       t        j                  | _         t        j                  t        j                  d       y )NzaPrevious SIGCHLD handler was set by non-Python code, restore to default handler on watcher close.F)r  rI   r  r  r   rf  rc   rQ   r  s     r   r  z!MultiLoopChildWatcher.attach_loop  so    
 !!-!'v~~t~~!N!!)NN J K%+^^D" 	FNNE2r   c                 Z    t        | j                        D ]  }| j                  |        y r    r  r  s     r   r  z%MultiLoopChildWatcher._do_waitpid_all  s(    ( 	"CS!	"r   c                 8   |dkD  sJ 	 t        j                  |t         j                        \  }}|dk(  ry t        |      }d}	 | j                  j                  |      \  }}}|j                         rt        j                  d||       y |r'|j                         rt        j                  d||        |j                  |||g|  y # t        $ r |}d}t        j                  d|       d}Y w xY w# t        $ r t        j                  d|d	       Y y w xY w)
Nr   Tr  r  F%Loop %r that handles pid %r is closedr  r  r>  )r!   r  r  r"   r  r   rf  r  r  	is_closedr  r#  r   r`   )	r+   r  r   r$   r   	debug_logr   rU   rV   s	            r   r  z!MultiLoopChildWatcher._do_waitpid  s   a	**\2::>KC ax/7JI	L#'??#6#6s#; D(D ~~FcR!1LL!G!-z;)))(CKdK= ! 	 CJNNJ I	$  	/ NND/	/s#   'C
 C5 
%C21C25!DDc                     	 | j                          y # t        t        f$ r  t        $ r t	        j
                  dd       Y y w xY w)Nr  Tr>  )r  r   r   r   r   rf  )r+   r   r   s      r   r  zMultiLoopChildWatcher._sig_chld<  sE    	R  "-. 	 	RNNADQ	Rs    /AAN)r   r   r   r   r)   rz   r1   r  r  r}   r  r  r  r  r  r   r   r   r   r     sA    	$.2
&3""#LJRr   r   c                   d    e Zd ZdZd Zd Zd Zd Zd Ze	j                  fdZd Zd	 Zd
 Zd Zy)r   aA  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                 F    t        j                  d      | _        i | _        y r   )	itertoolsr   _pid_counter_threadsr  s    r   r)   zThreadedChildWatcher.__init__R  s    %OOA.r   c                      yrF  r   r  s    r   rz   zThreadedChildWatcher.is_activeV  rq  r   c                      y r    r   r  s    r   r1   zThreadedChildWatcher.closeY  r  r   c                     | S r    r   r  s    r   r  zThreadedChildWatcher.__enter__\  r  r   c                      y r    r   r  s       r   r  zThreadedChildWatcher.__exit___  r  r   c                     t        | j                  j                               D cg c]  }|j                         r| }}|r || j                   dt
        |        y y c c}w )Nz0 has registered but not finished child processesr/   )r4   r  valuesis_aliver-   r8   )r+   r9  threadthreadss       r   r:  zThreadedChildWatcher.__del__b  sd    (,T]]-A-A-C(D )foo'  ) )T^^$$TU! )s   A!c                     t        j                         }t        j                  | j                  dt        | j                         ||||fd      }|| j                  |<   |j                          y )Nzasyncio-waitpid-T)targetnamerV   daemon)	r   r  r  Threadr  nextr  r  start)r+   r   rU   rV   r   r  s         r   r}   z&ThreadedChildWatcher.add_child_handlerj  sf    &&(!!)9)9)9$t?P?P:Q9R'S(,c8T'B)-/ $cr   c                      yrF  r   r  s     r   r  z)ThreadedChildWatcher.remove_child_handlers  r  r   c                      y r    r   r  s     r   r  z ThreadedChildWatcher.attach_loopy  r  r   c                    |dkD  sJ 	 t        j                  |d      \  }}t        |      }|j                         rt	        j
                  d||       	 |j                         rt	        j                  d||       n |j                  |||g|  | j                  j                  |       y # t        $ r |}d}t	        j                  d|       Y ~w xY w)Nr   r  r  r  r  )r!   r  r"   r  r   r#  r  rf  r  r   r  r  )r+   r   r  rU   rV   r   r$   r   s           r   r  z ThreadedChildWatcher._do_waitpid|  s    a	7**\15KC 07J~~C):7 >>NNBD#N%D%%hZG$G,'' ! 	 CJNNJ	s   B. .#CCN)r   r   r   r   r)   rz   r1   r  r  r6   r7   r:  r}   r  r  r  r   r   r   r   r   E  sB    
 %MM (r   r   c                      t        t        d      sy	 t        j                         } t        j                  t        j                  | d             y# t
        $ r Y yw xY w)Nr  Fr   T)hasattrr!   getpidr1   r  rM   )r   s    r   can_use_pidfdr&    sO    2|$iik
sA&'   s   =A 	AAc                   B     e Zd ZdZeZ fdZd Z fdZd Z	d Z
 xZS )_UnixDefaultEventLoopPolicyz:UNIX event loop policy with a watcher for child processes.c                 0    t         |           d | _        y r    )r(   r)   _watcherr  s    r   r)   z$_UnixDefaultEventLoopPolicy.__init__  s    r   c                     t         j                  5  | j                  )t               rt	               | _        nt               | _        d d d        y # 1 sw Y   y xY wr    )r   r  r*  r&  r   r   r  s    r   _init_watcherz)_UnixDefaultEventLoopPolicy._init_watcher  sA    \\ 	;}}$ ?$5$7DM$8$:DM	; 	; 	;s   6AAc                     t         |   |       | j                  Et        j                         t        j
                         u r| j                  j                  |       yyy)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*  r  current_threadmain_threadr  )r+   r   r-   s     r   r.  z*_UnixDefaultEventLoopPolicy.set_event_loop  sS     	t$MM%((*i.C.C.EEMM%%d+ F &r   c                     | j                   | j                          t        j                  ddd       | j                   S )z~Get the watcher for child processes.

        If not yet set, a ThreadedChildWatcher object is automatically created.
        ry   r  r  r  )r*  r,  r6   r  r  s    r   ry   z-_UnixDefaultEventLoopPolicy.get_child_watcher  s@    
 ==  0:BI	K }}r   c                     |t        |t              sJ | j                  | j                  j                          || _        t	        j
                  ddd       y)z$Set the watcher for child processes.Nset_child_watcherr  r  r  )rf   r   r*  r1   r6   r  )r+   r   s     r   r3  z-_UnixDefaultEventLoopPolicy.set_child_watcher  sT     *W6J"KKK==$MM!0:BI	Kr   )r   r   r   r   r&   _loop_factoryr)   r,  r.  ry   r3  r   r   s   @r   r(  r(    s%    D*M;,Kr   r(  )4r   rS   r   r  r!   r  rI   r   r   r  r2   r  r6    r   r   r   r   r   r	   r
   r   r   r   logr   __all__rT  ImportErrorr   r"   BaseSelectorEventLoopr&   ReadTransportrj   _FlowControlMixinWriteTransportrr   BaseSubprocessTransportr|   r   r   r  r   r   r   r   r&  BaseDefaultEventLoopPolicyr(  r   r   r   r   r   <module>r?     se   8  	  	      
              <<7
C
DD	
P"_BB P"f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   