python (3.12.0)

(root)/
lib/
python3.12/
asyncio/
__pycache__/
unix_events.cpython-312.opt-1.pyc

ˑepdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddl
mZddl
mZddl
mZddl
mZdd	l
mZdd
l
mZddl
mZddl
mZdd
l
mZddlmZdZe
j6dk(reddZdZGddej>Z GddejBZ"GddejFejHZ%GddejLZ'GddZ(Gdde(Z)Gd d!e(Z*Gd"d#e*Z+Gd$d%e*Z,Gd&d'e(Z-Gd(d)e(Z.d*Z/Gd+d,ej`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)SelectorEventLoopAbstractChildWatcherSafeChildWatcherFastChildWatcherPidfdChildWatcherMultiLoopChildWatcherThreadedChildWatcherDefaultEventLoopPolicywin32z+Signals are not really supported on Windowscy)zDummy signal handler.N)signumframes  G/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/asyncio/unix_events.py_sighandler_noopr*scP	tj|S#t$r|cYSwxYwN)oswaitstatus_to_exitcode
ValueError)statuss rr"r"/s.((00
	s%%ceZdZdZdfd	ZfdZdZdZdZdZ	d	Z
		dd
Z		ddZ	ddZ
d
Z	ddddddddZ	dddddddddZdZdZdZdZxZS)_UnixSelectorEventLoopzdUnix event loop.

    Adds signal handling and UNIX Domain Socket support to SelectorEventLoop.
    Nc2t||i|_yr )super__init___signal_handlers)selfselector	__class__s  rr)z_UnixSelectorEventLoop.__init__?s
" "rc0t|tjs,t	|j
D]}|j
|y|j
r;tjd|dt||j
jyy)NzClosing the loop z@ on interpreter shutdown stage, skipping signal handlers removalsource)r(closesys
is_finalizinglistr*remove_signal_handlerwarningswarnResourceWarningclear)r+sigr-s  rr1z_UnixSelectorEventLoop.closeCs

  "D112
0**3/
0$$

 1$:HI.%)	+
%%++-
%rc:|D]}|s|j|yr )_handle_signal)r+datars   r_process_self_dataz)_UnixSelectorEventLoop._process_self_dataQs%	(F'		(rcRtj|stj|rtd|j	||j	t
j|jjtj|||d}||j |<	t
j|t"t
j$|dy#ttf$r}tt|d}~wwxYw#t$r}|j |=|j sI	t
jdn2#ttf$r }t'j(d|Yd}~nd}~wwxYw|j*t*j,k(rtd|dd}~wwxYw)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()NFset_wakeup_fd(-1) failed: %ssig  cannot be caught)riscoroutineiscoroutinefunction	TypeError
_check_signal
_check_closedsignal
set_wakeup_fd_csockfilenor#OSErrorRuntimeErrorstrrHandler*rsiginterruptrinfoerrnoEINVAL)r+r:callbackargsexchandlenexcs       radd_signal_handlerz)_UnixSelectorEventLoop.add_signal_handlerXsq
""8,..x889
93	)

  !3!3!56xtT:%+c"	
MM#/0
U+G$	)s3x((	)	%%c*((F((,"G,FKK >EEFyyELL("T#.?#@AA	sZ-C-0D	D-DD		F&F!,EF!E1E,'F!,E110F!!F&c|jj|}|y|jr|j|y|j	|y)z2Internal helper that is the actual signal handler.N)r*get
_cancelledr5_add_callback_signalsafe)r+r:rXs   rr<z%_UnixSelectorEventLoop._handle_signalsE&&**3/>&&s+))&1rc|j|	|j|=|tjk(rtj
}ntj}	tj|||js	tjdyy#t$rYywxYw#t$r2}|jtjk(rtd|dd}~wwxYw#ttf$r }tjd|Yd}~yd}~wwxYw)zwRemove a handler for a signal.  UNIX only.

        Return True if a signal handler was removed, False if not.
        FrBrCNr@rAT)rGr*KeyErrorrISIGINTdefault_int_handlerSIG_DFLrMrSrTrNrJr#rrR)r+r:handlerrWs    rr5z,_UnixSelectorEventLoop.remove_signal_handlers
	
3	%%c*&--00GnnG	MM#w'$$
A$$R(-			yyELL("T#.?#@AA		(
A:C@@
AsA
BB8C	BB	C'-CCD+DDct|tstd||tjvrtd|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.
        zsig must be an int, not zinvalid signal number N)
isinstanceintrFrI
valid_signalsr#)r+r:s  rrGz$_UnixSelectorEventLoop._check_signalsJ#s#6sg>??f**,,5cU;<<-rc t|||||Sr )_UnixReadPipeTransportr+pipeprotocolwaiterextras     r_make_read_pipe_transportz0_UnixSelectorEventLoop._make_read_pipe_transports%dD(FEJJrc t|||||Sr )_UnixWritePipeTransportrks     r_make_write_pipe_transportz1_UnixSelectorEventLoop._make_write_pipe_transports&tT8VUKKrc	lKtj5tjdtt	j
}
ddd
5|
j
std|j}t||||||||f||d|	}|
j|j|j|	|d{	ddd|S#1swYxYw7#ttf$rt$r+|j!|j#d{7wxYw#1swYSxYww)NignorezRasyncio.get_child_watcher() is not activated, subprocess support is not installed.)rnro)r6catch_warningssimplefilterDeprecationWarningrget_child_watcher	is_activerN
create_future_UnixSubprocessTransportadd_child_handlerget_pid_child_watcher_callback
SystemExitKeyboardInterrupt
BaseExceptionr1_wait)
r+rmrVshellstdinstdoutstderrbufsizerokwargswatcherrntransps
             r_make_subprocess_transportz1_UnixSelectorEventLoop._make_subprocess_transports;
$
$
&	1!!(,>?..0G	1	$$&
#$GHH'')F-dHdE,16676396/56F
%%fnn&6$($@$@&
J
!	0
9	1	1( 12
 
lln$$
'	0
seD4/C
D4A-D'>C!CC!	
D4CD4C!!;D$DD$$D''D1,D4cR|j|j|j|yr )call_soon_threadsafe	call_soon_process_exited)r+pid
returncoders    rrz._UnixSelectorEventLoop._child_watcher_callbacks!!$..&2H2H*Ur)sslsockserver_hostnamessl_handshake_timeoutssl_shutdown_timeoutcK|r
|2td|td|td|td||tdtj|}tjtjtj
d}	|j
d|j||d{nf|td|jtjk7s|jtj
k7rtd	||j
d|j||||||
d{\}}	||	fS7#|jxYw7#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 timerFzno path and sock were specified.A UNIX Domain Stream Socket was expected, got )rr)r#r!fspathsocketAF_UNIXSOCK_STREAMsetblockingsock_connectr1familytype_create_connection_transport)
r+protocol_factorypathrrrrr	transportrms
          rcreate_unix_connectionz-_UnixSelectorEventLoop.create_unix_connections& EGG* !NOO$0 GII#/ FHH IKK99T?D==1C1CQGD
  '''d333| !BCCv~~-II!3!33 DTHMOOU#$($E$E"C"7!5%F%77	8(""%4


7s=BE#&E7E	8E<BE#=E!>E#	EEE#dT)rbacklogrrr
start_servingc	Kt|trtd|
|std|
|std||tdt	j
|}t
jtjtj}|ddvrH	tjt	j|jrt	j|	|j#|nU|td
|j*tjk7s|j,tjk7rtd||j/dt1j2||g|||||}|r-|j5t7j8dd{|S#t$rYt$r!}	tj d||	Yd}	~	d}	~	wwxYw#t$rT}
|j%|
j&t&j(k(r!d|d	}tt&j(|dd}
~
w|j%xYw7w)
Nz*ssl argument must be an SSLContext or Nonerrrr)rz2Unable to check or remove stale UNIX socket %r: %rzAddress z is already in usez-path was not specified, and no sock specifiedrF)rfboolrFr#r!rrrrstatS_ISSOCKst_moderemoveFileNotFoundErrorrMrerrorbindr1rS
EADDRINUSErrrrServer_start_servingrsleep)
r+rrrrrrrrerrrWmsgservers
             rcreate_unix_serverz)_UnixSelectorEventLoop.create_unix_servers7c4 HII ,SCE
E +CBD
D IKK99T?D==1C1CDDAwk)6}}RWWT]%:%:;		$

		$| CEEv~~-II!3!33 DTHMOO	
##D4&2B$'2G$8:!!#++a.  
S)6LL"*+/666


99 0 00%TH,>?C!%"2"2C8dB


&
!siBIAF'"G3B-I I!I'	G0I2G:GIGI	I'AH66IIc
K	tj	|j}	tj|j}|r|n|}|sy|j}	|j|	d|||||d|	d{S#t$rtjdwxYw#ttjf$r}tjdd}~wwxYw#t$rtjdwxYw7~w)Nzos.sendfile() is not availableznot a regular filer)
r!sendfileAttributeErrorr	SendfileNotAvailableErrorrLioUnsupportedOperationfstatst_sizerMr{_sock_sendfile_native_impl)
r+rfileoffsetcountrLrfsize	blocksizefuts
          r_sock_sendfile_nativez,_UnixSelectorEventLoop._sock_sendfile_nativecs	2KK	M[[]F	MHHV$,,E#E	  "''T4(.y!	Ey%	26602
2	2
 7 78	M667KLL	M	M667KLL	MsVC<BB"C6C<;C:<C<BC<"C;CCC<C77C<c	
|j}	||j||jr|j|||y|r/||z
}|dkr%|j||||j	|y	tj|	|||}
|
dk(r%|j||||j	|y||
z
}||
z
}||j|||j|	|j||	||||||
y#ttf$r;||j|||j|	|j||	||||||
Yyt$r}|Q|jtjk(r4t|t ur#t!dtj}||_|}|dk(r:t%j&d}
|j||||j)|
n)|j||||j)|Yd}~yYd}~yd}~wt*t,f$rt.$r.}|j||||j)|Yd}~yd}~wwxYw)Nrzsocket is not connectedzos.sendfile call failed)rL
remove_writer	cancelled_sock_sendfile_update_filepos
set_resultr!r_sock_add_cancellation_callback
add_writerrBlockingIOErrorInterruptedErrorrMrSENOTCONNrConnectionError	__cause__r	r
set_exceptionrrr)r+r
registered_fdrrLrrr
total_sentfdsentrWnew_excrs              rrz1_UnixSelectorEventLoop._sock_sendfile_native_implzsT
[[]$

}-==?..vvzJ
*IA~2266:Nz*1	F;;r669=DJqy2266:Nz*$d"
 (88dCD$C$CS "D& &y*F[ !12	B$44S$?OOB ? ?f"E9j
B	')II/I_4
*-u~~?$'!Q
!::-/2266:N!!#&2266:N!!#&&'-.		#..vvzJc""	#s,:C??AIIB6HI+$IIcZ|dkDr&tj||tjyyNr)r!lseekSEEK_SET)r+rLrrs    rrz4_UnixSelectorEventLoop._sock_sendfile_update_fileposs">HHVVR[[1rc6fd}|j|y)Ncv|jr(j}|dk7rj|yyy)Nr@)rrLr)rrr+rs  rcbzB_UnixSelectorEventLoop._sock_add_cancellation_callback.<locals>.cbs6}}[[]8&&r*r)add_done_callback)r+rrrs` ` rrz6_UnixSelectorEventLoop._sock_add_cancellation_callbacks	+
	b!rr NN)__name__
__module____qualname____doc__r)r1r>rZr<r5rGrprsrrrrrrrr
__classcell__r-s@rr&r&9s
#.(+Z2@
=@D(,KAE)-L04BV
*.0#4 "&!%0#f*.Gs"&!%GR.DFL2"rr&ceZdZdZdfd	ZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZej fd
ZddZdZdZxZS)rjic4t||||jd<||_||_|j|_||_d|_d|_	tj|jj}tj|sJtj|s5tj |s d|_d|_d|_t#dtj$|jd|jj'|jj(||jj'|j*|j|j,|,|jj't.j0|dyy)NrlFz)Pipe transport is for pipes/sockets only.)r(r)_extra_loop_piperL_fileno	_protocol_closing_pausedr!rrrS_ISFIFOrS_ISCHRr#set_blockingrconnection_made_add_reader_read_readyr
_set_result_unless_cancelled)r+looprlrmrnromoder-s       rr)z_UnixReadPipeTransport.__init__s.
"F

{{}!
xx%--

d#

d#T"DJDL!DNHII
e,

T^^;;TB

T--!\\4+;+;	=JJ  !E!E!'
/rc^|jsy|jj||yr )
is_readingrr)r+rrUs   rrz"_UnixReadPipeTransport._add_readers# 

r8,rc:|jxr
|jSr )rrr+s rrz!_UnixReadPipeTransport.is_readings<<5

$55rct|jjg}|j|jdn|jr|jd|jd|j
t
|jdd}|jW|Utj||j
tj}|r|jdnA|jdn/|j|jdn|jddjd	j|S)
Nclosedclosingfd=	_selectorpollingidleopen<{}> )r-rrappendrrgetattrrr_test_selector_event	selectors
EVENT_READformatjoin)r+rRr,rs    r__repr__z_UnixReadPipeTransport.__repr__s''(::KK!
]]KK	"c$,,()4::{D9::!h&:%::$,,	(<(<>GI&F#
ZZ
#KKKK!}}SXXd^,,rch	tj|j|j}|r|jj|y|jjrtjd|d|_
|jj|j|jj|jj|jj|jdy#tt f$rYyt"$r}|j%|dYd}~yd}~wwxYw)N%r was closed by peerTz"Fatal read error on pipe transport)r!readrmax_sizer
data_receivedr	get_debugrrRr_remove_readerreof_received_call_connection_lostrrrM_fatal_error)r+r=rWs   rrz"_UnixReadPipeTransport._read_readys	G774<<7D,,T2::'')KK 7> $


))$,,7

$$T^^%@%@A

$$T%?%?F !12		Ic#GHH	Is*C<<D1
D1D,,D1c|jsyd|_|jj|j|jjrt
jd|yy)NTz%r pauses reading)rrrrrrrdebugrs r
pause_readingz$_UnixReadPipeTransport.pause_readingsP 

!!$,,/::!LL,d3"rc|js|jsyd|_|jj|j|j
|jj
rtjd|yy)NFz%r resumes reading)	rrrrrrrrr#rs rresume_readingz%_UnixReadPipeTransport.resume_reading&s[==

t||T-=-=>::!LL-t4"rc||_yr rr+rms  rset_protocolz#_UnixReadPipeTransport.set_protocol.	!rc|jSr r(rs rget_protocolz#_UnixReadPipeTransport.get_protocol1~~rc|jSr rrs r
is_closingz!_UnixReadPipeTransport.is_closing4}}rc@|js|jdyyr )r_closers rr1z_UnixReadPipeTransport.close7s}}KKrcv|j-|d|t||jjyyNzunclosed transport r/rr8r1r+_warns  r__del__z_UnixReadPipeTransport.__del__;5::!'x0/$OJJ"rc<t|trQ|jtjk(r4|jjrDt
jd||dn*|jj||||jd|j|yNz%r: %sTexc_info)message	exceptionrrm)rfrMrSEIOrrrr#call_exception_handlerrr4r+rWr@s   rr!z#_UnixReadPipeTransport._fatal_error@srsG$eii)?zz##%XtWtDJJ--" ! NN	/
	
Crcd|_|jj|j|jj	|j
|yNT)rrrrrr r+rWs  rr4z_UnixReadPipeTransport._closeNs9


!!$,,/

T77=rc	|jj||jjd|_d|_d|_y#|jjd|_d|_d|_wxYwr rconnection_lostrr1rrGs  rr z,_UnixReadPipeTransport._call_connection_lostSg	NN**3/JJDJ!DNDJ
JJDJ!DNDJA

1A>rzFatal error on pipe transport)rrrrr)rrrrr$r&r*r-r1r1r6r7r:r!r4r rrs@rrjrjs]H/<-
6-*G$45"%MM
>
rrjceZdZdfd	ZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZej fd
ZdZddZddZdZxZS)rrct
|||||jd<||_|j	|_||_t|_d|_	d|_
tj|j
j}tj|}tj |}tj"|}	|s$|s"|	s d|_d|_d|_t%dtj&|j
d|j(j+|jj,||	s!|rdt.j0j3dsE|j(j+|j(j4|j
|j6|,|j(j+t8j:|dyy)NrlrFz?Pipe transport is only for pipes, sockets and character devicesaix)r(r)rrrLrr	bytearray_buffer
_conn_lostrr!rrrrrrr#rrrrr2platform
startswithrrr
r)r+rrlrmrnroris_charis_fifo	is_socketr-s          rr)z _UnixWritePipeTransport.__init__`si
%"F
{{}! {
xx%--,,t$--%MM$'	7iDJDL!DNDE
E	e,

T^^;;TB
)@)@)GJJ  !7!7!%t/?/?
AJJ  !E!E!'
/rc|jjg}|j|jdn|jr|jd|jd|j
t
|jdd}|j{|ytj||j
tj}|r|jdn|jd|j}|jd|n/|j|jdn|jdd	jd
j|S)Nrrr	r
rrzbufsize=r
rr)r-rrrrrrrrrrEVENT_WRITEget_write_buffer_sizerr)r+rRr,rrs     rrz _UnixWritePipeTransport.__repr__s''(::KK!
]]KK	"c$,,()4::{D9::!h&:%::$,,	(=(=?GI&F#002GKK(7),-
ZZ
#KKKK!}}SXXd^,,rc,t|jSr )lenrRrs rr[z-_UnixWritePipeTransport.get_write_buffer_sizes4<<  rc|jjrtjd||jr|jt
y|jy)Nr)rrrrRrRr4BrokenPipeErrorrs rrz#_UnixWritePipeTransport._read_readys@::!KK/6<<KK)*KKMrct|trt|}|sy|js|jrH|jt
jk\rtjd|xjdz
c_y|jss	tj|j|}|t'|k(ry|dkDrt||d}|j(j+|j|j,|xj|z
c_	|j/y#ttf$rd}Ytt f$rt"$r1}|xjdz
c_|j%|dYd}~yd}~wwxYw)Nz=pipe closed by peer or os.write(pipe, data) raised exception.rr#Fatal write error on pipe transport)rfrQ
memoryviewrSrr!LOG_THRESHOLD_FOR_CONNLOST_WRITESrwarningrRr!writerrrrrrr!r]r_add_writer_write_ready_maybe_pause_protocol)r+r=nrWs    rrez_UnixWritePipeTransport.writes7dI&d#D??dmm)"M"MM HIOOq O||	
HHT\\40CI~Q!$'+JJ""4<<1B1BC""$$%56
 12
 
1$!!#'LM
s D$$E?7E?'E::E?c	tj|j|j}|t	|jk(r|jj|jj|j|j|jr6|jj|j|jdy|dkDr|jd|=yy#ttf$rYyttf$rt $rp}|jj|xj"dz
c_|jj|j|j%|dYd}~yd}~wwxYw)Nrrra)r!rerrRr]r9r_remove_writer_maybe_resume_protocolrrr rrrrrrSr!)r+rirWs   rrgz$_UnixWritePipeTransport._write_readys.	%t||4AC%%""$

))$,,7++-==JJ--dll;..t4QLL!$) !12	-.		JLL OOq O
JJ%%dll3c#HII
	Js*C,,F=FA&E??FcyrFrrs r
can_write_eofz%_UnixWritePipeTransport.can_write_eofrc|jryd|_|jsL|jj|j|jj|jdyyrF)rrRrrrrr rs r	write_eofz!_UnixWritePipeTransport.write_eofsO==
||JJ%%dll3JJ  !;!;TBrc||_yr r(r)s  rr*z$_UnixWritePipeTransport.set_protocolr+rc|jSr r(rs rr-z$_UnixWritePipeTransport.get_protocolr.rc|jSr r0rs rr1z"_UnixWritePipeTransport.is_closingr2rcX|j|js|jyyyr )rrrqrs rr1z_UnixWritePipeTransport.closes$::!$--NN+8!rcv|j-|d|t||jjyyr6r7r8s  rr:z_UnixWritePipeTransport.__del__r;rc&|jdyr )r4rs rabortz_UnixWritePipeTransport.abortsDrct|tr4|jjrDt	j
d||dn*|jj
||||jd|j|yr=)	rfrMrrrr#rCrr4rDs   rr!z$_UnixWritePipeTransport._fatal_error
scc7#zz##%XtWtDJJ--" ! NN	/
	
Crc>d|_|jr%|jj|j|jj|jj
|j|jj|j|yrF)	rrRrrkrr9rrr rGs  rr4z_UnixWritePipeTransport._closesf
<<JJ%%dll3

!!$,,/

T77=rc	|jj||jjd|_d|_d|_y#|jjd|_d|_d|_wxYwr rIrGs  rr z-_UnixWritePipeTransport._call_connection_lost rKrLrrMr )rrrr)rr[rrergrnrqr*r-r1r1r6r7r:rxr!r4r rrs@rrrrr]sd#/J-0!!%F%8C"
%MM
>rrrceZdZdZy)r|c
d}|tjk(r6tjj	drtj\}}	tj|f||||d|d||_|=|jt|jd||j_d}|!|j|jyy#|!|j|jwwxYw)NrPF)rrrruniversal_newlinesrwb)	buffering)
subprocessPIPEr2rTrUr
socketpairPopen_procr1r
detachr)	r+rVrrrrrrstdin_ws	         r_startz_UnixSubprocessTransport._start,sJOO#(?(?(F
$..0NE7	 #))E!vf#('E=CEDJ"
#'(8$'#R

 "


#w"


#s

A!C%C7N)rrrrrrrr|r|*s rr|cBeZdZdZddZdZdZdZdZdZ	d	Z
d
Zy)raHAbstract base class for monitoring child processes.

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

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

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

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

        Since child watcher objects may catch the SIGCHLD signal and call
        waitpid(-1), there should be only one active object per process.
    Nc\|jtk7rtjdddyy)NrP{name!r} is deprecated as of Python 3.12 and will be removed in Python {remove}.r)rrr6_deprecated)clss r__init_subclass__z&AbstractChildWatcher.__init_subclass__Ys,>>X%  !7;%,
.&rct)aRegister a new child handler.

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

        Note: callback() must be thread-safe.
        NotImplementedErrorr+rrUrVs    rr}z&AbstractChildWatcher.add_child_handler`s
"##rct)zRemoves the handler for process 'pid'.

        The function returns True if the handler was successfully removed,
        False if there was nothing to remove.rr+rs  rremove_child_handlerz)AbstractChildWatcher.remove_child_handlerks
"##rct)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.
        rr+rs  rattach_loopz AbstractChildWatcher.attach_loopss
"##rct)zlClose the watcher.

        This must be called to make sure that any underlying resource is freed.
        rrs rr1zAbstractChildWatcher.close}s

"##rct)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.

        rrs rrzzAbstractChildWatcher.is_actives
"##rct)zdEnter the watcher's context and allow starting new processes

        This function must return selfrrs r	__enter__zAbstractChildWatcher.__enter__s
"##rct)zExit the watcher's contextrr+abcs    r__exit__zAbstractChildWatcher.__exit__s!##r)returnN)rrrrrr}rrr1rzrrrrrrrBs/,.	$$$$$$$rrc@eZdZdZdZdZdZdZdZdZ	dZ
d	Zy
)ra6Child watcher implementation using Linux's pid file descriptors.

    This child watcher polls process file descriptors (pidfds) to await child
    process termination. In some respects, PidfdChildWatcher is a "Goldilocks"
    child watcher implementation. It doesn't require signals or threads, doesn't
    interfere with any processes launched outside the event loop, and scales
    linearly with the number of subprocesses launched by the event loop. The
    main disadvantage is that pidfds are specific to Linux, and only work on
    recent (5.3+) kernels.
    c|Sr rrs rrzPidfdChildWatcher.__enter__rcyr r)r+exc_type	exc_value
exc_tracebacks    rrzPidfdChildWatcher.__exit__rcyrFrrs rrzzPidfdChildWatcher.is_activerorcyr rrs rr1zPidfdChildWatcher.closerrcyr rrs  rrzPidfdChildWatcher.attach_looprrctj}tj|}|j	||j
||||yr )rget_running_loopr!
pidfd_openr_do_wait)r+rrUrVrpidfds      rr}z#PidfdChildWatcher.add_child_handlers:&&(

c"

sE8TJrc$tj}|j|	tj|d\}}t|}tj||||g|y#t$rd}tjd|YCwxYw)NrzJchild process pid %d exit status already read:  will report returncode 255)
rrrr!waitpidr"ChildProcessErrorrrdr1)	r+rrrUrVr_r$rs	         rrzPidfdChildWatcher._do_waits&&(E"	8

3*IAv07J
j(4(!	JNN.
		sA++!BBcyrFrrs  rrz&PidfdChildWatcher.remove_child_handlerrN)rrrrrrrzr1rr}rrrrrrrs0	


K
)&rrc6eZdZdZdZdZdZdZdZdZ	y)	BaseChildWatcherc d|_i|_yr )r
_callbacksrs rr)zBaseChildWatcher.__init__s
rc&|jdyr )rrs rr1zBaseChildWatcher.closesrcV|jduxr|jjSr )r
is_runningrs rrzzBaseChildWatcher.is_actives#zz%A$***?*?*AArctr r)r+expected_pids  r_do_waitpidzBaseChildWatcher._do_waitpid!##rctr rrs r_do_waitpid_allz BaseChildWatcher._do_waitpid_allrrc^|j(|&|jrtjdt|j)|jjtj||_|;|jtj|j|jyy)NzCA loop is being detached from a child watcher with pending handlers)rrr6r7RuntimeWarningr5rISIGCHLDrZ	_sig_chldrrs  rrzBaseChildWatcher.attach_loops::!dltMM=
 
::!JJ,,V^^<
##FNNDNNC
  "rc	|jy#ttf$rt$r(}|jjd|dYd}~yd}~wwxYw)N$Unknown exception in SIGCHLD handler)r@rA)rrrrrrCrGs  rrzBaseChildWatcher._sig_chldsX	  "-.		
JJ--A /

		sAAAN)
rrrr)r1rzrrrrrrrrrs&B$$#(rrcPeZdZdZfdZfdZdZdZdZdZ	dZ
d	ZxZS)
rad'Safe' child watcher implementation.

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

    This is a safe solution but it has a significant overhead when handling a
    big number of children (O(n) each time SIGCHLD is raised)
    cRt|tjdddy)Nrrrr)r(r)r6rr+r-s rr)zSafeChildWatcher.__init__s'
/;%,	.rcV|jjt|
yr )rr9r(r1rs rr1zSafeChildWatcher.closes

rc|Sr rrs rrzSafeChildWatcher.__enter__rrcyr rrs    rrzSafeChildWatcher.__exit__ rrcH||f|j|<|j|yr )rrrs    rr}z"SafeChildWatcher.add_child_handler#s% ($/	
rc>	|j|=y#t$rYywxYwNTFrr`rs  rrz%SafeChildWatcher.remove_child_handler)(	$		
	cZt|jD]}|j|yr r4rrrs  rrz SafeChildWatcher._do_waitpid_all0s((	"CS!	"rc	tj|tj\}}|dk(ryt|}|jjrt
jd||		|jj|\}}|||g|y#t$r|}d}t
jd|YOwxYw#t$r7|jjrt
jd|dYyYywxYw)Nr$process %s exited with returncode %sr8Unknown child process pid %d, will report returncode 255'Child watcher got an unexpected pid: %rTr>)
r!rWNOHANGr"rrrr#rrdrpopr`)r+rrr$rrUrVs       rrzSafeChildWatcher._do_waitpid5s	7**\2::>KCax/7Jzz##%C):7		-!__005NHd
S*,t,7!	CJNNJ
	(	3zz##%H"T3&	3s#'B-B?#B<;B<?;C?>C?)
rrrrr)r1rrr}rrrrrs@rrrs0.
"
 -rrcJeZdZdZfdZfdZdZdZdZdZ	dZ
xZS)	raW'Fast' child watcher implementation.

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

    There is no noticeable overhead when handling a big number of children
    (O(1) each time a child terminates).
    ct|tj|_i|_d|_tjdddy)Nrrrrr)	r(r)	threadingLock_lock_zombies_forksr6rrs rr)zFastChildWatcher.__init__bsC
^^%

/;%,	.rc|jj|jjt|yr )rr9rr(r1rs rr1zFastChildWatcher.closels,



rct|j5|xjdz
c_|cdddS#1swYyxYw)Nr)rrrs rrzFastChildWatcher.__enter__qs/
ZZ	KK1K			s.7c>|j5|xjdzc_|js|js
	dddyt|j}|jj	dddtjdy#1swY xYw)Nrz5Caught subprocesses termination from unknown pids: %s)rrrrOr9rrd)r+rrrcollateral_victimss     rrzFastChildWatcher.__exit__ws{
ZZ	"KK1K{{$--		"	""%T]]!3MM!	"	C	 	"	"s/B/BBc|j5	|jj|}	ddd||g|y#t$r||f|j|<YdddywxYw#1swY<xYwr )rrrr`r)r+rrUrVrs     rr}z"FastChildWatcher.add_child_handlerszZZ	
!]]..s3
		j(4(

'/~$
		
		s&A&>A#A&"A##A&&A/c>	|j|=y#t$rYywxYwrrrs  rrz%FastChildWatcher.remove_child_handlerrrc		tjdtj\}}|dk(ryt|}|j
5	|jj|\}}|jjrtjd||	dddtjd||n
|||g#t$rYywxYw#t$r\|jrK||j|<|jjrtjd||Yddd4d}YwxYw#1swYxYw)Nr@rrz,unknown process %s exited with returncode %sz8Caught subprocess termination from unknown pid: %d -> %d)r!rrr"rrrrrrrr#r`rrrd)r+rr$rrUrVs      rrz FastChildWatcher._do_waitpid_allsC

< jjRZZ8V
!83F;

66%)__%8%8%=NHdzz++-%K%(*6!
6& #Z1j040K%

 
${{-7

c*:://1"LL*>),j:!
6
6 $H
$
6
6sN'CD=	C'2D=	CCAD:*D=5D:7D=9D::D==E)rrrrr)r1rrr}rrrrs@rrrXs+.
 )(1rrcReZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZy
)ra~A watcher that doesn't require running loop in the main thread.

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

    The solution is safe but it has a significant overhead when
    handling a big number of processes (*O(n)* each time a
    SIGCHLD is received).
    cPi|_d|_tjdddy)Nrrrr)r_saved_sighandlerr6rrs rr)zMultiLoopChildWatcher.__init__s*!%4;%,	.rc|jduSr )rrs rrzzMultiLoopChildWatcher.is_actives%%T11rcZ|jj|jytjtj
}||jk7rtjdd|_ytjtj
|jd|_y)Nz+SIGCHLD handler was changed by outside code)	rr9rrI	getsignalrrrrd)r+rds  rr1zMultiLoopChildWatcher.closesz!!)""6>>2dnn$NNHI"&
MM&..$*@*@A!%rc|Sr rrs rrzMultiLoopChildWatcher.__enter__rrcyr rr+rexc_valexc_tbs    rrzMultiLoopChildWatcher.__exit__rrcrtj}|||f|j|<|j|yr )rrrr)r+rrUrVrs     rr}z'MultiLoopChildWatcher.add_child_handlers5&&( $h5	
rc>	|j|=y#t$rYywxYwrrrs  rrz*MultiLoopChildWatcher.remove_child_handlerrrc8|jytjtj|j|_|j*t	j
dtj|_tjtjdy)NzaPrevious SIGCHLD handler was set by non-Python code, restore to default handler on watcher close.F)rrIrrrrdrcrQrs  rrz!MultiLoopChildWatcher.attach_loopso
!!-!'v~~t~~!N!!)NNJ
K%+^^D"	FNNE2rcZt|jD]}|j|yr rrs  rrz%MultiLoopChildWatcher._do_waitpid_alls((	"CS!	"rc*	tj|tj\}}|dk(ryt|}d}	|jj|\}}}|jrtjd||y|r'|jrtjd|||j|||g|y#t$r|}d}tjd|d}YwxYw#t$rtjd|d	YywxYw)
NrTrrF%Loop %r that handles pid %r is closedrrr>)r!rrr"rrrdrr	is_closedrr#rr`)	r+rrr$r	debug_logrrUrVs	         rrz!MultiLoopChildWatcher._do_waitpids
	**\2::>KCax/7JI	L#'??#6#6s#; D(D~~FcR!1LL!G!-z;)))(CKdK=!	CJNNJ
I	$	/
NND
/	/s"'CC.%C+*C+.!DDc	|jy#ttf$rt$rt	j
ddYywxYw)NrTr>)rrrrrrd)r+rrs   rrzMultiLoopChildWatcher._sig_chld=sE	R  "-.		RNNADQ	Rs/AAN)rrrrr)rzr1rrr}rrrrrrrrrrsA	$.2
&
3""#LJRrrcjeZdZdZdZdZdZdZdZdZ	e
jfdZd	Z
d
ZdZdZy
)raAThreaded child watcher implementation.

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

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

    The watcher has O(1) complexity, its performance doesn't depend
    on amount of spawn processes.
    cFtjd|_i|_yr)	itertoolsr_pid_counter_threadsrs rr)zThreadedChildWatcher.__init__Ss%OOA.
rcyrFrrs rrzzThreadedChildWatcher.is_activeWrorc$|jyr )
_join_threadsrs rr1zThreadedChildWatcher.closeZsrct|jjDcgc] }|jr|js|"}}|D]}|jycc}w)z%Internal: Join all non-daemon threadsN)r4rvaluesis_alivedaemonr)r+threadthreadss   rrz"ThreadedChildWatcher._join_threads]s](,T]]-A-A-C(D?foo'

??	FKKM	?s%A%c|Sr rrs rrzThreadedChildWatcher.__enter__drrcyr rrs    rrzThreadedChildWatcher.__exit__grrct|jjDcgc]}|jr|}}|r||jdt
|yycc}w)Nz0 has registered but not finished child processesr/)r4rrrr-r8)r+r9rrs    rr:zThreadedChildWatcher.__del__jsd(,T]]-A-A-C(D)foo'))T^^$$TU!
)sA!ctj}tj|jdt|j||||fd}||j|<|jy)Nzwaitpid-T)targetnamerVr)	rrrThreadrnextrrstart)r+rrUrVrrs      rr}z&ThreadedChildWatcher.add_child_handlerrsf&&(!!)9)9)1$t7H7H2I1J'K(,c8T'B)-/$

crcyrFrrs  rrz)ThreadedChildWatcher.remove_child_handler{rrcyr rrs  rrz ThreadedChildWatcher.attach_looprrc	tj|d\}}t|}|jrt	j
d||	|jrt	jd||n|j|||g||jj|y#t$r|}d}t	jd|Y~wxYw)Nrrrrr)r!rr"rrr#rrdrrrr)r+rrrUrVrr$rs        rrz ThreadedChildWatcher._do_waitpids	7**\15KC07J~~C):7>>NNBD#N%D%%hZG$G

,''!	CJNNJ
	sB''#C
C
N)rrrrr)rzr1rrrr6r7r:r}rrrrrrrrFsG

%MM
(rrcttdsy	tj}tjtj|dy#t
$rYywxYw)NrFrT)hasattrr!getpidr1rrM)rs r
can_use_pidfdr%sO2|$iik
sA&'s=A	AAcBeZdZdZeZfdZdZfdZdZ	dZ
xZS)_UnixDefaultEventLoopPolicyz:UNIX event loop policy with a watcher for child processes.c0t|d|_yr )r(r)_watcherrs rr)z$_UnixDefaultEventLoopPolicy.__init__s

rcftj5|jtrt	|_nt|_t
jt
jur/|jj|jjdddy#1swYyxYwr )rrr)r%rrrcurrent_threadmain_threadr_localrrs r
_init_watcherz)_UnixDefaultEventLoopPolicy._init_watchers{
\\	A}}$ ?$5$7DM$8$:DM++-1F1F1HHMM--dkk.?.?@	A	A	AsB
B''B0ct|||jEtjtj
ur|jj
|yyy)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)rr+r,r)r+rr-s  rr0z*_UnixDefaultEventLoopPolicy.set_event_loopsS	t$MM%((*i.C.C.EEMM%%d+F
&rc|j|jtjddd|jS)z~Get the watcher for child processes.

        If not yet set, a ThreadedChildWatcher object is automatically created.
        ryrrr)r)r.r6rrs rryz-_UnixDefaultEventLoopPolicy.get_child_watchers@
==  0:BI	K}}rc|j|jj||_tjdddy)z$Set the watcher for child processes.Nset_child_watcherrrr)r)r1r6r)r+rs  rr3z-_UnixDefaultEventLoopPolicy.set_child_watchers?
==$MM!
0:BI	Kr)rrrrr&
_loop_factoryr)r.r0ryr3rrs@rr'r's&D*MA,Krr')4rrSrr
r!rrIrrrr2rr6rrrrrr	r
rrr
logr__all__rTImportErrorrr"BaseSelectorEventLoopr&
ReadTransportrj_FlowControlMixinWriteTransportrrBaseSubprocessTransportr|rrrrrrrr%BaseDefaultEventLoopPolicyr'rrrrr<module>r?se8		


<<7
C
DD	
Q"_BBQ"hMZ55M`Jj::(77JZ FF 0S$S$l7,7t2+2jN-'N-bj1'j1Z~R0~RBV(/V(p	8K&"C"C8Kv+4r