eSrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK r SSK r SSK r SSK r SSK Jr SSK Jr SSK Jr SSK Jr SSK Jr SS K Jr SS K Jr SS K Jr SS K Jr SS K Jr SSKJr Sr\ R6S:Xa\"S5eSrSr"SS\R>5r "SS\RB5r""SS\RF\RH5r%"SS\RL5r'"SS5r("SS\(5r)"S S!\(5r*"S"S#\*5r+"S$S%\*5r,"S&S'\(5r-"S(S)\(5r.S*r/"S+S,\R`5r1\ 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) SelectorEventLoopAbstractChildWatcherSafeChildWatcherFastChildWatcherPidfdChildWatcherMultiLoopChildWatcherThreadedChildWatcherDefaultEventLoopPolicy EventLoopwin32z+Signals are not really supported on Windowscg)zDummy signal handler.N)signumframes 9/opt/imh/python3.13/lib/python3.13/asyncio/unix_events.py_sighandler_noopr+scT[R"U5$![a Us$f=fN)oswaitstatus_to_exitcode ValueError)statuss rr#r#0s.((00  s  ''c ^\rSrSrSrSU4SjjrU4SjrSrSrSr S r S r SS jr SS jr SS jrSrSSSSSSS.SjjrSSSSSSSSS.SjjrSrSrSrSrU4SjrSrU=r$)_UnixSelectorEventLoop:z\Unix event loop. Adds signal handling and UNIX Domain Socket support to SelectorEventLoop. Nc@>[TU]U5 0Ul0Ulgr!)super__init___signal_handlers_unix_server_sockets)selfselector __class__s rr+_UnixSelectorEventLoop.__init__@s  " "$&!rcH>[TU]5 [R"5(d.[ UR 5HnUR U5 M gUR (a:[R"SU<S3[US9 UR R5 gg)NzClosing the loop z@ on interpreter shutdown stage, skipping signal handlers removalsource) r*closesys is_finalizinglistr,remove_signal_handlerwarningswarnResourceWarningclear)r.sigr0s rr5_UnixSelectorEventLoop.closeEs    ""D112**3/3$$ 1$:HI.%) + %%++- %rcJUHnU(dM URU5 M gr!)_handle_signal)r.datars r_process_self_data)_UnixSelectorEventLoop._process_self_dataSs F    ' rc[R"U5(d"U5(a [S5eUR U5 UR 5 [ R"URR55 [R"X#US5nXPR U'[ R "U["5 [ R$"US5 g![[4an[[U55eSnAff=f![anUR U UR (dL[ R"S5 O4![[4a!n[&R("SU5 SnAOSnAff=fUR*[*R,:Xa[SUS35eeSnAff=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()NFset_wakeup_fd(-1) failed: %ssig  cannot be caught)r iscoroutineiscoroutinefunction TypeError _check_signal _check_closedsignal set_wakeup_fd_csockfilenor$OSError RuntimeErrorstrrHandler,r siginterruptrinfoerrnoEINVAL)r.r>callbackargsexchandlenexcs radd_signal_handler)_UnixSelectorEventLoop.add_signal_handlerZss  " "8 , ,..x8889 9 3  )  !3!3!5 6xtT:%+c"  MM#/ 0   U +G$ )s3x( ( ) %%c*((F((,"G,FKK >EEFyyELL("T#.?#@AA sZ$.C,92D,D<DD F?"F:EF:F (F?F:F  1F::F?cURRU5nUcgUR(aURU5 gUR U5 g)z2Internal helper that is the actual signal handler.N)r,get _cancelledr9_add_callback_signalsafe)r.r>r^s rrA%_UnixSelectorEventLoop._handle_signalsE&&**3/ >      & &s +  ) )& 1rc4URU5 URU U[R:Xa[R nO[R n[R"X5 UR(d[R"S5 gg![a gf=f![a3nUR[R:Xa[SUS35eeSnAff=f![[4a!n[R"SU5 SnAgSnAff=f)zgRemove a handler for a signal. UNIX only. Return True if a signal handler was removed, False if not. FrHrINrFrGT)rMr,KeyErrorrOSIGINTdefault_int_handlerSIG_DFLrSrYrZrTrPr$rrX)r.r>handlerr]s rr9,_UnixSelectorEventLoop.remove_signal_handlers 3 %%c* &-- 00GnnG  MM# '$$ A$$R(-   yyELL("T#.?#@AA  ( A :C@@ AsA BB&>C& B#"B#& C#0.CC#&D6DDc[U[5(d[SU<35eU[R"5;a[ SU35eg)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) isinstanceintrLrO valid_signalsr$)r.r>s rrM$_UnixSelectorEventLoop._check_signalsM #s##6sg>? ? f**, ,5cU;< < -rc[XX#U5$r!)_UnixReadPipeTransportr.pipeprotocolwaiterextras r_make_read_pipe_transport0_UnixSelectorEventLoop._make_read_pipe_transports%d(EJJrc[XX#U5$r!)_UnixWritePipeTransportrus r_make_write_pipe_transport1_UnixSelectorEventLoop._make_write_pipe_transports&t8UKKrc # [R"5 [R"S[5 [R "5n SSS5 W  U R 5(d [S5eUR5n [XX#XEXg4XS.U D6n U RU R5URU 5 U IShvN SSS5 U $!,(df  N=fN ![[4a e[a+ U R!5 U R#5IShvN ef=f!,(df  W $=f7f)NignorezRasyncio.get_child_watcher() is not activated, subprocess support is not installed.)rxry)r:catch_warnings simplefilterDeprecationWarningrget_child_watcher is_activerT create_future_UnixSubprocessTransportadd_child_handlerget_pid_child_watcher_callback SystemExitKeyboardInterrupt BaseExceptionr5_wait) r.rwr\shellstdinstdoutstderrbufsizerykwargswatcherrxtransps r_make_subprocess_transport1_UnixSelectorEventLoop._make_subprocess_transports) $ $ &  ! !(,> ?..0G'$$&& #$GHH'')F-dd,166396/56F  % %fnn&6$($@$@& J  !0 9' &( 12    lln$$ 'W0 seE1C EA-D1C)C'C) E C$ E'C))=D.&D)'D..D11 E;Ec<URURU5 gr!)call_soon_threadsafe_process_exited)r.pid returncoders rr._UnixSelectorEventLoop._child_watcher_callbacks !!&"8"8*Er)sslsockserver_hostnamessl_handshake_timeoutssl_shutdown_timeoutc # Ub[U[5(deU(aUc [S5eO*Ub [S5eUb [S5eUb [S5eUbUb [S5e[R"U5n[ R "[ R [ RS5nURS5 URXB5IShvN OjUc [S5eUR[ R :wdUR[ R:wa[S U<35eURS5 URXAX5UUS 9IShvN upX4$N! UR5 e=fN!7f) 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)rorUr$r"fspathsocketAF_UNIX SOCK_STREAM setblocking sock_connectr5familytype_create_connection_transport) r.protocol_factorypathrrrrr transportrws rcreate_unix_connection-_UnixSelectorEventLoop.create_unix_connections &*_c*J*JJJ & EGG'* !NOO$0 GII#/ FHH   IKK99T?D==1C1CQGD   '''333 | !BCC v~~-II!3!33 DTHMOO   U #$($E$E C"7!5%F%77 ""%4  7s=B6F9%E/E-E/#BF#F$ F-E//FFdT)rbacklogrrr start_servingcleanup_socketc # [U[5(a [S5eUbU(d [S5eUbU(d [S5eUbUb [S5e[R "U5n[ R "[ R[ R5nUSS;aP[R"[R"U5R5(a[R"U5 UR#U5 OYUc [S 5eUR*[ R:wdUR,[ R:wa[S U<35eU (aGUR/5nUSS;a.[R"U5R0UR2U'UR5S 5 [6R8"X/UXTUU5n U(a.U R;5 [<R>"S5IShvN U $![a GN*[a"n [R "SX*5 Sn A GNPSn A ff=f![aVn UR%5 U R&[&R(:Xa"SU<S 3n [[&R(U 5SeeSn A f UR%5 e=f![a GNf=fN7f) 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) roboolrLr$r"rrrrstatS_ISSOCKst_moderemoveFileNotFoundErrorrSrerrorbindr5rY EADDRINUSErr getsocknamest_inor-rrServer_start_servingr sleep)r.rrrrrrrrrerrr]msgservers rcreate_unix_server)_UnixSelectorEventLoop.create_unix_servers c4 HI I ,SCE E +CBD D   IKK99T?D==1C1CDDAwk)6}}RWWT]%:%:;; $  $| CEE v~~-II!3!33 DTHMOO ##%DAwk)68ggdm6J6JD--d3 ##D&2B$'2G$8:   ! ! #++a.  e)6LL"*+/666  99 0 00%TH,>?C!%"2"2C8dB  ") !sB.K1AHIA:K -K :AKKK I'K* I3I KIK K "AJ33K  K KKKKc # [R UR 5n[R"U5RnU(aUOUnU(dgUR5n URU SXX4US5 U IShvN $![a [R"S5ef=f![[ R4an[R"S5eSnAff=f![a [R"S5ef=fN7f)Nzos.sendfile() is not availableznot a regular filer) r"sendfileAttributeErrorr SendfileNotAvailableErrorrRioUnsupportedOperationfstatst_sizerSr_sock_sendfile_native_impl) r.rfileoffsetcountrRrfsize blocksizefuts r_sock_sendfile_native,_UnixSelectorEventLoop._sock_sendfile_nativems 2 KK M[[]F MHHV$,,E#E   " ''T4(.y! Ey% 26602 2 2  7 78 M667KL L M M667KL L MsVD B B- C%>D D D  !B**D -C"CC""D %!DD c UR5n UbURU5 UR5(aURXEU5 gU(a.Xh- nUS::a$URXEU5 UR U5 g[ U[ RS-S-5n[R"XXW5n U S:Xa$URXEU5 UR U5 gXZ- nX- nUcURX5 URXRUXUXVXx5 g![[4a7 UcURX5 URXRUXUXVXx5 g[an UbRU R [ R":Xa4[%U 5[&La"['S[ R"5n XlU n US:Xa>[*R,"S5n URXEU5 UR/U 5 Sn A gURXEU5 UR/U 5 Sn A gSn A f[0[24a e[4a-n URXEU5 UR/U 5 Sn A gSn A ff=f)Nrrzsocket is not connectedzos.sendfile call failed)rR remove_writer cancelled_sock_sendfile_update_filepos set_resultminr6maxsizer"r_sock_add_cancellation_callback add_writerrBlockingIOErrorInterruptedErrorrSrYENOTCONNrConnectionError __cause__r r set_exceptionrrr)r.r registered_fdrrRrrr total_sentfdsentr]new_excrs rr1_UnixSelectorEventLoop._sock_sendfile_native_implsA [[]  $   } - ==??  . .vz J  *IA~226:Nz* 3;;>A#56 1 F;;r6=DJqy226:Nz*"  (88C$C$CS "& &yF[ !12 B$44S? OOB ? ?f"9 B ')II/I_4 *-u~~?$'!Q !::-/226:N!!#&&226:N!!#&&-.   #  . .vz J   c " " #s2#D!!AI;' I;0BH1 #H11I;#I66I;c\US:a&[R"X[R5 ggNr)r"lseekSEEK_SET)r.rRrrs rr4_UnixSelectorEventLoop._sock_sendfile_update_fileposs > HHVR[[ 1 rc8^^UU4SjnURU5 g)Nc>UR5(a)TR5nUS:waTRU5 ggg)NrF)rrRr)rrr.rs rcbB_UnixSelectorEventLoop._sock_add_cancellation_callback..cbs8}}[[]8&&r*r)add_done_callback)r.rrrs` ` rr6_UnixSelectorEventLoop._sock_add_cancellation_callbacks + b!rc>XR;aUR5nOSn[TU] U5 UbYURUnURU [R "U5R U:Xa[R"U5 ggg![a g[a!n[R"SX$5 SnAgSnAff=f)Nz/Unable to clean up listening UNIX socket %r: %r) r-rr* _stop_servingr"rrunlinkrrSrr)r.rrprev_inorr0s rr$_UnixSelectorEventLoop._stop_servings ,, ,##%DD d#  006H))$/ 2774=''83IIdO4  %  2 &'+22 2s:B C C%CC)r,r-r!NN)__name__ __module__ __qualname____firstlineno____doc__r+r5rCr`rAr9rMrzr~rrrrrrrrr__static_attributes__ __classcell__r0s@rr'r':s ' .(+Z2@ =@D(,KAE)-L 04BF*.0#4 "&!% 0#f*.Ps"&!%t Pd.GFR2"22rr'c^\rSrSrSrSU4SjjrSrSrSrSr Sr S r S r S r S rS r\R"4SjrSSjrSrSrSrU=r$)rtiicV>[TU]U5 X RS'XlX lUR 5UlX0lSUlSUl [R"UR 5Rn[R"U5(dV[R"U5(d;[R "U5(d SUlSUlSUl[#S5e[R$"UR S5 URR'URR(U5 URR'UR*UR UR,5 Ub,URR'[.R0US5 gg)NrvFz)Pipe transport is for pipes/sockets only.)r*r+_extra_loop_piperR_fileno _protocol_closing_pausedr"rrrS_ISFIFOrS_ISCHRr$ set_blocking call_soonconnection_made _add_reader _read_readyr _set_result_unless_cancelled)r.looprvrwrxrymoder0s rr+_UnixReadPipeTransport.__init__s/ " F  {{} !  xx %-- d## d## T""DJDL!DNHI I  e, T^^;;TB T--!\\4+;+; =   JJ !E!E!' / rcfUR5(dgURRX5 gr!) is_readingrr)r.rr[s rr"_UnixReadPipeTransport._add_readers$   r,rcTUR(+=(a UR(+$r!)rrr.s rr&!_UnixReadPipeTransport.is_readings<<5 $55rcURR/nURcURS5 O"UR(aURS5 URSUR 35 [ URSS5nURb]UbZ[R"X R [R5nU(aURS5 OBURS5 O0URbURS5 OURS5 SRS RU55$) Nclosedclosingfd= _selectorpollingidleopen<{}> )r0r rappendrrgetattrrr _test_selector_event selectors EVENT_READformatjoin)r.rXr/r0s r__repr___UnixReadPipeTransport.__repr__s''( ::  KK ! ]] KK " c$,,()4::{D9 :: !h&:%::,, (<(<>G I& F# ZZ # KK  KK !}}SXXd^,,rc[R"URUR5nU(aURR U5 gUR R5(a[R"SU5 SUl UR RUR5 UR RURR5 UR RURS5 g![[ 4a g["anUR%US5 SnAgSnAff=f)N%r was closed by peerTz"Fatal read error on pipe transport)r"readrmax_sizer data_receivedr get_debugrrXr_remove_readerr eof_received_call_connection_lostrrrS _fatal_error)r.rBr]s rr "_UnixReadPipeTransport._read_ready.s G774<<7D ,,T2::''))KK 7> $  ))$,,7 $$T^^%@%@A $$T%?%?F !12   I   c#G H H Is+DD? D?#D::D?cUR5(dgSUlURRUR5 URR 5(a[ R"SU5 gg)NTz%r pauses reading)r&rrrDrrCrdebugr)s r pause_reading$_UnixReadPipeTransport.pause_reading@sV    !!$,,/ ::   ! ! LL,d 3 "rc&UR(dUR(dgSUlURRURUR 5 URR 5(a[R"SU5 gg)NFz%r resumes reading) rrrrrr rCrrJr)s rresume_reading%_UnixReadPipeTransport.resume_readingHs^ ==   t||T-=-=> ::   ! ! LL-t 4 "rcXlgr!rr.rws r set_protocol#_UnixReadPipeTransport.set_protocolP!rcUR$r!rQr)s r get_protocol#_UnixReadPipeTransport.get_protocolS ~~rcUR$r!rr)s r is_closing!_UnixReadPipeTransport.is_closingV }}rcJUR(dURS5 ggr!)r_closer)s rr5_UnixReadPipeTransport.closeYs}} KK rctURb+U"SU<3[US9 URR5 ggNzunclosed transport r3rr<r5r._warns r__del___UnixReadPipeTransport.__del__]5 :: ! 'x0/$ O JJ    "rcL[U[5(aTUR[R:Xa6URR 5(a[ R"SXSS9 O*URRUUUURS.5 URU5 gNz%r: %sTexc_info)message exceptionrrw) rorSrYEIOrrCrrJcall_exception_handlerrr`r.r]rns rrG#_UnixReadPipeTransport._fatal_errorbsw sG $ $eii)?zz##%% XttD JJ - -" ! NN /  CrcSUlURRUR5 URR UR U5 gNT)rrrDrrrFr.r]s rr`_UnixReadPipeTransport._closeps9  !!$,,/ T77=rcURRU5 URR5 SUlSUlSUlg!URR5 SUlSUlSUlf=fr!rconnection_lostrr5rrvs rrF,_UnixReadPipeTransport._call_connection_lostug  NN * *3 / JJ   DJ!DNDJ JJ   DJ!DNDJ A 1A>)rrrrrrrzFatal error on pipe transport)r r r r rAr+rr&r<r rKrNrSrWr\r5r:r;rgrGr`rFrrrs@rrtrtsbH/<- 6-*G$45"%MM > rrtc^\rSrSrSU4SjjrSrSrSrSrSr Sr S r S r S r S rS r\R"4SjrSrSSjrSSjrSrSrU=r$)r}ic>[T U]XQ5 X RS'X lUR 5UlX0l[5UlSUl SUl [R"UR 5Rn[R"U5n[R "U5n[R""U5n U(d.U(d'U (d SUlSUlSUl[%S5e[R&"UR S5 UR(R+UR R,U5 U (d+U(ai[.R0R3S5(dEUR(R+UR(R4UR UR65 Ub,UR(R+[8R:US5 gg)NrvrFz?Pipe transport is only for pipes, sockets and character devicesaix)r*r+rrrRrr bytearray_buffer _conn_lostrr"rrrrrrr$rrrrr6platform startswithrr r r!) r.r"rvrwrxryr#is_charis_fifo is_socketr0s rr+ _UnixWritePipeTransport.__init__sd %" F {{} ! {  xx %--,,t$--%MM$' 7iDJDL!DNDE E  e, T^^;;TB )@)@)G)G JJ !7!7!%t/?/? A   JJ !E!E!' / rcURR/nURcURS5 O"UR(aURS5 URSUR 35 [ URSS5nURbUb~[R"X R [R5nU(aURS5 OURS5 UR5nURSU35 O0URbURS5 OURS5 S RS RU55$) Nr,r-r.r/r0r1zbufsize=r2r3r4)r0r rr5rrr6rr r7r8 EVENT_WRITEget_write_buffer_sizer:r;)r.rXr/r0rs rr< _UnixWritePipeTransport.__repr__s ''( ::  KK ! ]] KK " c$,,()4::{D9 :: !h&:%::,, (=(=?G I& F#002G KK(7), - ZZ # KK  KK !}}SXXd^,,rc,[UR5$r!)lenrr)s rr-_UnixWritePipeTransport.get_write_buffer_sizes4<<  rcURR5(a[R"SU5 UR(aUR [ 55 gUR 5 g)Nr?)rrCrrXrr`BrokenPipeErrorr)s rr #_UnixWritePipeTransport._read_readysC ::   ! ! KK/ 6 << KK) * KKMrc[U[[[45(d[ U55e[U[5(a [U5nU(dgUR (dUR (aJUR [R:a[R"S5 U=R S- slgUR(dv[R"URU5nU[+U5:XagUS:a[U5USnUR,R/URUR05 U=RU- sl UR35 g![[ 4a SnN["[$4a e[&a1nU=R S- slUR)US5 SnAgSnAff=f)Nz=pipe closed by peer or os.write(pipe, data) raised exception.rr#Fatal write error on pipe transport)robytesr memoryviewreprrrr!LOG_THRESHOLD_FOR_CONNLOST_WRITESrwarningrr"writerrrrrrrGrr _add_writer _write_ready_maybe_pause_protocol)r.rBnr]s rr_UnixWritePipeTransport.writes]$ : >??KdK? dI & &d#D  ??dmm)"M"MM HI OOq O || HHT\\40CI~Q!$'+ JJ " "4<<1B1B C   ""$$%56  12   1$!!#'LM s!E22GG'G  GcTUR(dS5e[R"URUR5nU[ UR5:XaURR 5 UR RUR5 UR5 UR(a6UR RUR5 URS5 gUS:aURSU2 gg![[4a g[[4a e[ apnURR 5 U=R"S- slUR RUR5 UR%US5 SnAgSnAff=f)NzData should not be emptyrrr)rr"rrrr=r_remove_writer_maybe_resume_protocolrrDrFrrrrrrrG)r.rr]s rr$_UnixWritePipeTransport._write_readys@||777| %t||4AC %% ""$ ))$,,7++-==JJ--dll;..t4QLL!$) !12  -.   J LL   OOq O JJ % %dll 3   c#H I I  Js+D F'F'7A&F""F'cgrurr)s r can_write_eof%_UnixWritePipeTransport.can_write_eof rcUR(agUR(deSUlUR(dLURR UR 5 URR URS5 ggru)rrrrrDrrrFr)s r write_eof!_UnixWritePipeTransport.write_eof s[ == zzz || JJ % %dll 3 JJ !;!;T BrcXlgr!rQrRs rrS$_UnixWritePipeTransport.set_protocolrUrcUR$r!rQr)s rrW$_UnixWritePipeTransport.get_protocolrYrcUR$r!r[r)s rr\"_UnixWritePipeTransport.is_closingr^rcdURb#UR(dUR5 gggr!)rrrr)s rr5_UnixWritePipeTransport.closes$ :: !$-- NN +8 !rctURb+U"SU<3[US9 URR5 ggrcrdres rrg_UnixWritePipeTransport.__del__$rirc&URS5 gr!)r`r)s rabort_UnixWritePipeTransport.abort)s Drc[U[5(a6URR5(a[R "SXSS9 O*URR UUUURS.5 URU5 grk) rorSrrCrrJrqrr`rrs rrG$_UnixWritePipeTransport._fatal_error,sh c7 # #zz##%% XttD JJ - -" ! NN /  CrcHSUlUR(a%URRUR5 URR 5 URR UR5 URRURU5 gru) rrrrrr=rDrrFrvs rr`_UnixWritePipeTransport._close:sf << JJ % %dll 3  !!$,,/ T77=rcURRU5 URR5 SUlSUlSUlg!URR5 SUlSUlSUlf=fr!ryrvs rrF-_UnixWritePipeTransport._call_connection_lostBr|r})rrrrrrrrr~r!)r r r r r+r<rr rrrrrSrWr\r5r:r;rgrrGr`rFrrrs@rr}r}si#/J-0!!%F%8C" %MM  >rr}c\rSrSrSrSrg)riLc SnU[R:Xa;[RR S5(a[ R "5up8[R"U4X#XESUS.UD6UlUb:UR5 [UR5SUS9URl SnUb!UR5 UR5 gg!Ub!UR5 UR5 ff=f)NrF)rrrruniversal_newlinesrwb) buffering) subprocessPIPEr6rrr socketpairPopen_procr5r2detachr) r.r\rrrrrrstdin_ws r_start_UnixSubprocessTransport._startNs JOO # (?(?(F(F $..0NE #))E!v#('E=CEDJ" #'(8$'#R  "  #w"  #s AC&C<)rN)r r r r rrrrrrrLs rrcL\rSrSrSrS SjrSrSrSrSr S r S r S r S r g)rida 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. NcZUR[:wa[R"SSSS9 gg)NrP{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;%, . &rc[5e)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. NotImplementedErrorr.rr[r\s rr&AbstractChildWatcher.add_child_handlers "##rc[5e)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_handler)AbstractChildWatcher.remove_child_handlers "##rc[5e)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.r"s r attach_loop AbstractChildWatcher.attach_loops "##rc[5e)z\Close the watcher. This must be called to make sure that any underlying resource is freed. rr)s rr5AbstractChildWatcher.closes "##rc[5e)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. rr)s rrAbstractChildWatcher.is_actives "##rc[5e)z\Enter the watcher's context and allow starting new processes This function must return selfrr)s r __enter__AbstractChildWatcher.__enter__s "##rc[5e)zExit the watcher's contextrr.abcs r__exit__AbstractChildWatcher.__exit__s !##rr)returnN)r r r r r rrrrr5rrrrrrrrrds/,. $$$$$$ $rrcH\rSrSrSrSrSrSrSrSr Sr S r S r S r g ) riaChild 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. cU$r!rr)s rrPidfdChildWatcher.__enter__ rcgr!r)r.exc_type exc_value exc_tracebacks rrPidfdChildWatcher.__exit__ rcgrurr)s rrPidfdChildWatcher.is_activerrcgr!rr)s rr5PidfdChildWatcher.closerrcgr!rrs rrPidfdChildWatcher.attach_looprrc[R"5n[R"U5nUR XPR XX#5 gr!)rget_running_loopr" pidfd_openr_do_wait)r.rr[r\r"pidfds rr#PidfdChildWatcher.add_child_handlers4&&( c"  s8Jrc*[R"5nURU5 [R"US5upg[ U5n[R"U5 U"X/UQ76 g![ a Sn[R"SU5 NEf=f)NrzJchild process pid %d exit status already read: will report returncode 255) rrrDr"waitpidr#ChildProcessErrorrrr5) r.rr r[r\r"_r%rs rrPidfdChildWatcher._do_waits&&( E" 8 3*IA07J (4(! J NN.   sA,,#BBcgrurrs rr&PidfdChildWatcher.remove_child_handlerrrN)r r r r r rrrr5rrrrrrrrrrs0    K )&rrc>\rSrSrSrSrSrSrSrSr Sr S r g ) BaseChildWatcheric SUl0Ulgr!)r _callbacksr)s rr+BaseChildWatcher.__init__s rc&URS5 gr!)rr)s rr5BaseChildWatcher.closes rc`URSL=(a URR5$r!)r is_runningr)s rrBaseChildWatcher.is_actives#zz%A$***?*?*AArc[5er!r)r. expected_pids r _do_waitpidBaseChildWatcher._do_waitpid !##rc[5er!rr)s r_do_waitpid_all BaseChildWatcher._do_waitpid_allr"rcUb![U[R5(deURb/Uc,UR(a[ R "S[5 URb)URR[R5 XlUb;UR[RUR5 UR5 gg)NzCA loop is being detached from a child watcher with pending handlers)rorAbstractEventLooprrr:r;RuntimeWarningr9rOSIGCHLDr` _sig_chldr$rs rrBaseChildWatcher.attach_loops|z$0H0HIIII :: !dlt MM= :: ! JJ , ,V^^ <    # #FNNDNN C  " rcUR5 g![[4a e[a(nURR SUS.5 SnAgSnAff=f)N$Unknown exception in SIGCHLD handler)rnro)r$rrrrrqrvs rr*BaseChildWatcher._sig_chldsX   "-.    JJ - -A /    sAAA)rrN) r r r r r+r5rr r$rr*rrrrrrs&B$$#( rrc\^\rSrSrSrU4SjrU4SjrSrSrSr Sr S r S r S r U=r$) ri)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) cN>[TU]5 [R"SSSS9 g)Nrrrr)r*r+r:rr.r0s rr+SafeChildWatcher.__init__4s' /;%, .rcV>URR5 [TU] 5 gr!)rr=r*r5r1s rr5SafeChildWatcher.close;s   rcU$r!rr)s rrSafeChildWatcher.__enter__?rrcgr!rrs rrSafeChildWatcher.__exit__BrrcFX#4URU'URU5 gr!)rr rs rr"SafeChildWatcher.add_child_handlerEs# (/ rc@URU g![a gf=fNTFrrhrs rr%SafeChildWatcher.remove_child_handlerK( $    c^[UR5HnURU5 M gr!r8rr rs rr$ SafeChildWatcher._do_waitpid_allRs#(C   S !)rc&US:de[R"U[R5up#US:Xag[U5nURR 5(a[ R"SX5 URRU5upVU"X$/UQ76 g![a UnSn[ R"SU5 NOf=f![a: URR 5(a[ R"SUSS9 ggf=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#rrCrrJrrrpoprh)r.rrr%rr[r\s rr SafeChildWatcher._do_waitpidWsa 7**\2::>KCax/7Jzz##%% C)7 -!__005NH S ,t ,7! CJ NNJ   ( 3zz##%%H"T3& 3s#'B!:C !%C C  ?DDr)r r r r r r+r5rrrrr$r rrrs@rrr)s5.  " - -rrcV^\rSrSrSrU4SjrU4SjrSrSrSr Sr S r S r U=r $) riza?'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>[TU]5 [R"5Ul0UlSUl[R"SSSS9 g)Nrrrrr) r*r+ threadingLock_lock_zombies_forksr:rr1s rr+FastChildWatcher.__init__sC ^^%   /;%, .rc>URR5 URR5 [TU]5 gr!)rr=rPr*r5r1s rr5FastChildWatcher.closes,    rc~UR U=RS- slUsSSS5 $!,(df  g=f)Nr)rOrQr)s rrFastChildWatcher.__enter__s$ ZZ KK1 KZZs. <c^UR U=RS-slUR(dUR(d SSS5 g[UR5nURR 5 SSS5 [ R "SW5 g!,(df  N&=f)Nrz5Caught subprocesses termination from unknown pids: %s)rOrQrPrUr=rr)r.rrrcollateral_victimss rrFastChildWatcher.__exit__sp ZZ KK1 K{{$-- Z "%T]]!3  MM   !  C  Zs9B/B B,cUR(dS5eUR URRU5nSSS5 U"UW/UQ76 g![a X#4UR U'SSS5 gf=f!,(df  NA=f)NzMust use the context manager)rQrOrPrIrhr)r.rr[r\rs rr"FastChildWatcher.add_child_handlers}{{:::{ ZZ !]]..s3  j(4(  '/~$ Z Zs(A>AA;0A>:A;;A>> B c@URU g![a gf=fr<r=rs rr%FastChildWatcher.remove_child_handlerr?r@c[R"S[R5upUS:Xag[U5nUR  UR RU5upEURR5(a[R"SX5 SSS5 Wc[R"SX5 O U"X/WQ76 M![a gf=f![af UR(aPX0RU'URR5(a[R"SX5 SSS5 GMESnNf=f!,(df  N=f)NrFrrEz,unknown process %s exited with returncode %sz8Caught subprocess termination from unknown pid: %d -> %d)r"r rHr#rrOrrIrrCrrJrhrQrPr)r.rr%rr[r\s rr$ FastChildWatcher._do_waitpid_alls0 < jjRZZ8  !83F; 6%)__%8%8%=NHzz++-- %K%(6!& #1040K%   ${{-7 c*:://11"LL*>),:! $H $sN'C E C'6E CCAE :EE E E  E E)rQrOrP)r r r r r r+r5rrrrr$rrrs@rrrzs0.    )(1(1rrcZ\rSrSrSrSrSrSrSrSr Sr S r S r S r S rS rSrg)riabA 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). cL0UlSUl[R"SSSS9 g)Nrrrr)r_saved_sighandlerr:rr)s rr+MultiLoopChildWatcher.__init__s*!%4;%, .rcURSL$r!)rbr)s rrMultiLoopChildWatcher.is_actives%%T11rcTURR5 URcg[R"[R 5nXR :wa[R"S5 O/[R"[R UR5 SUlg)Nz+SIGCHLD handler was changed by outside code) rr=rbrO getsignalr)r*rr)r.rls rr5MultiLoopChildWatcher.closesl   ! ! ) ""6>>2 nn $ NNH I MM&..$*@*@ A!%rcU$r!rr)s rrMultiLoopChildWatcher.__enter__rrcgr!rr.rexc_valexc_tbs rrMultiLoopChildWatcher.__exit__rrcr[R"5nXBU4URU'URU5 gr!)rrrr )r.rr[r\r"s rr'MultiLoopChildWatcher.add_child_handlers3&&( $5 rc@URU g![a gf=fr<r=rs rr*MultiLoopChildWatcher.remove_child_handlerr?r@cBURbg[R"[RUR5UlURc+[R "S5 [R Ul[R"[RS5 g)NzaPrevious SIGCHLD handler was set by non-Python code, restore to default handler on watcher close.F)rbrOr)r*rrrkrWrs rr!MultiLoopChildWatcher.attach_loop%so  ! ! - !'v~~t~~!N  ! ! ) NNJ K%+^^D " FNNE2rc^[UR5HnURU5 M gr!rBrs rr$%MultiLoopChildWatcher._do_waitpid_all6s#(C   S !)rcXUS:de[R"U[R5up#US:Xag[U5nSnURRU5upgnUR5(a[ R "SXb5 gU(a,UR5(a[ R"SX5 UR"XrU/UQ76 g![a UnSn[ R "SU5 SnNf=f![a [ R "SUSS 9 gf=f) NrTr rFF%Loop %r that handles pid %r is closedrErGrl)r"r rHr#rrrrrI is_closedrCrJrrh) r.rrr%r debug_logr"r[r\s rr !MultiLoopChildWatcher._do_waitpid:sa **\2::>KCax/7JI L#'??#6#6s#; DD~~FR!1!1LL!G!-;))(KdK=! CJ NNJ I $ / NND / /s#'CD'DD D)(D)cUR5 g![[4a e[a [R "SSS9 gf=f)Nr-Trl)r$rrrrr)r.rrs rr*MultiLoopChildWatcher._sig_chld_sE R  "-.   R NNAD Q Rs/AA)rrbN)r r r r r r+rr5rrrrrr$r r*rrrrrrsA $.2 & 3""#LJRrrcn\rSrSrSrSrSrSrSrSr \ R4Sjr S r S rS rS rS rg)riha%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. cH[R"S5Ul0Ulgr) itertoolsr _pid_counter_threadsr)s rr+ThreadedChildWatcher.__init__us%OOA. rcgrurr)s rrThreadedChildWatcher.is_activeyrrcgr!rr)s rr5ThreadedChildWatcher.close|rrcU$r!rr)s rrThreadedChildWatcher.__enter__rrcgr!rrls rrThreadedChildWatcher.__exit__rrc[URR55Vs/sHnUR5(dMUPM nnU(aU"URS3[ US9 ggs snf)Nz0 has registered but not finished child processesr3)r8rvaluesis_aliver0r<)r.rfthreadthreadss rrgThreadedChildWatcher.__del__se(,T]]-A-A-C(D)(Dfoo'(D)  T^^$$TU!  )s A-A-c[R"5n[R"URS[ UR 53XAX#4SS9nXPRU'UR5 g)Nzasyncio-waitpid-T)targetnamer\daemon) rrrMThreadr nextrrstart)r.rr[r\r"rs rr&ThreadedChildWatcher.add_child_handlers`&&(!!)9)9)9$t?P?P:Q9R'S(,8'B)-/$ c rcgrurrs rr)ThreadedChildWatcher.remove_child_handlerrrcgr!rrs rr ThreadedChildWatcher.attach_looprrcUS:de[R"US5upV[U5nUR5(a[R "SX'5 UR5(a[R"SX5 OUR"X5U/UQ76 URRU5 g![ a UnSn[R"SU5 Nf=f)NrrEr rFry) r"r r#rCrrJrrrzrrrI)r.r"rr[r\rr%rs rr  ThreadedChildWatcher._do_waitpidsa 7**\15KC07J~~ C)7 >>   NNBD N  % %hZ G$ G ,''! CJ NNJ   sB77%CC)rrN)r r r r r r+rr5rrr:r;rgrrrr rrrrrrhsB   %MM  (rrc[[S5(dg[R"5n[R"[R"US55 g![ a gf=f)NrFrT)hasattrr"getpidr5rrS)rs r can_use_pidfdrsR 2| $ $iik sA&'  sAA A&%A&cN^\rSrSrSr\rU4SjrSrU4Sjr Sr Sr Sr U=r $) _UnixDefaultEventLoopPolicyiz:UNIX event loop policy with a watcher for child processes.c0>[TU]5 SUlgr!)r*r+_watcherr1s rr+$_UnixDefaultEventLoopPolicy.__init__s  rc[R URc.[5(a[ 5UlO[ 5UlSSS5 g!,(df  g=fr!)rrOrrrrr)s r _init_watcher)_UnixDefaultEventLoopPolicy._init_watchers8 \\}}$ ??$5$7DM$8$:DM \\s [TU]U5 URbH[R"5[R "5LaURR U5 ggg)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_looprrMcurrent_thread main_threadr)r.r"r0s rr*_UnixDefaultEventLoopPolicy.set_event_loopsS t$ MM %((*i.C.C.EE MM % %d +F &rcURcUR5 [R"SSSS9 UR$)znGet the watcher for child processes. If not yet set, a ThreadedChildWatcher object is automatically created. rrrr)rrr:rr)s rr-_UnixDefaultEventLoopPolicy.get_child_watchers@ ==    0:BI K}}rcUb[U[5(deURbURR5 Xl[R "SSSS9 g)z$Set the watcher for child processes.Nset_child_watcherrrr)rorrr5r:r)r.rs rr-_UnixDefaultEventLoopPolicy.set_child_watchersU*W6J"K"KKK == $ MM   ! 0:BI Kr)r)r r r r r r' _loop_factoryr+rrrrrrrs@rrrs+D*M; ,  K Krr)5r rYrrr"r8rOrrrr6rMr:rrrrrr r r r r logr__all__r ImportErrorrr#BaseSelectorEventLoopr' ReadTransportrt_FlowControlMixinWriteTransportr}BaseSubprocessTransportrrrrrrrrrBaseDefaultEventLoopPolicyrrrrrrrrsj8     <<7 C DD r2_BBr2j MZ55M`Jj::(77JZ FF 0S$S$l7,7t2+2jN-'N-bj1'j1Z~R0~RBO(/O(b 6K&"C"C6Kr+4  r