? GR0V Shell

GR0V shell

Linux in-mum-web921.main-hosting.eu 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64

Path : /lib64/python3.8/asyncio/__pycache__/
File Upload :
Current File : //lib64/python3.8/asyncio/__pycache__/unix_events.cpython-38.opt-1.pyc

U

e5dۿ@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddl
mZddl
mZddl
mZddl
mZdd	l
mZdd
l
mZddl
mZddl
mZdd
l
mZddlmZdZe
jdkredddZGdddejZGdddej Z!Gdddej"ej#Z$Gdddej%Z&GdddZ'ddZ(Gd d!d!e'Z)Gd"d#d#e)Z*Gd$d%d%e)Z+Gd&d'd'e'Z,Gd(d)d)e'Z-Gd*d+d+ej.Z/eZ0e/Z1dS),z2Selector event loop for Unix with signal handling.N)base_events)base_subprocess)	constants)
coroutines)events)
exceptions)futures)selector_events)tasks)
transports)logger)SelectorEventLoopAbstractChildWatcherSafeChildWatcherFastChildWatcherMultiLoopChildWatcherThreadedChildWatcherDefaultEventLoopPolicyZwin32z+Signals are not really supported on WindowscCsdS)zDummy signal handler.N)signumframerr+/usr/lib64/python3.8/asyncio/unix_events.py_sighandler_noop*srcseZdZdZd)fdd	ZfddZddZd	d
ZddZd
dZ	ddZ
d*ddZd+ddZd,ddZ
ddZd-dddddddZd.dddddddd Zd!d"Zd#d$Zd%d&Zd'd(ZZS)/_UnixSelectorEventLoopzdUnix event loop.

    Adds signal handling and UNIX Domain Socket support to SelectorEventLoop.
    Ncst|i|_dSN)super__init___signal_handlers)selfselector	__class__rrr5sz_UnixSelectorEventLoop.__init__csZtts.t|jD]}||qn(|jrVtjd|dt	|d|j
dS)NzClosing the loop z@ on interpreter shutdown stage, skipping signal handlers removalsource)rclosesys
is_finalizinglistrremove_signal_handlerwarningswarnResourceWarningclearrsigr!rrr%9s
z_UnixSelectorEventLoop.closecCs|D]}|sq||qdSr)_handle_signal)rdatarrrr_process_self_dataGsz)_UnixSelectorEventLoop._process_self_datac
GsLt|st|rtd|||zt|j	Wn2t
tfk
rt}ztt
|W5d}~XYnXt|||d}||j|<zt|tt|dWntk
rF}zz|j|=|jsztdWn4t
tfk
r}ztd|W5d}~XYnX|jtjkr4td|dnW5d}~XYnXdS)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)rZiscoroutineZiscoroutinefunction	TypeError
_check_signalZ
_check_closedsignal
set_wakeup_fdZ_csockfileno
ValueErrorOSErrorRuntimeErrorstrrZHandlerrsiginterruptr
infoerrnoEINVAL)rr/callbackargsexchandleZnexcrrradd_signal_handlerNs2


z)_UnixSelectorEventLoop.add_signal_handlercCs8|j|}|dkrdS|jr*||n
||dS)z2Internal helper that is the actual signal handler.N)rgetZ
_cancelledr)Z_add_callback_signalsafe)rr/rGrrrr0{sz%_UnixSelectorEventLoop._handle_signalc
Cs||z|j|=Wntk
r,YdSX|tjkr@tj}ntj}zt||WnBtk
r}z$|jtj	krt
d|dnW5d}~XYnX|jsztdWn2ttfk
r}zt
d|W5d}~XYnXdS)zwRemove a handler for a signal.  UNIX only.

        Return True if a signal handler was removed, False if not.
        Fr5r6Nr3r4T)r8rKeyErrorr9SIGINTdefault_int_handlerSIG_DFLr=rBrCr>r:r<r
rA)rr/handlerrFrrrr)s(

z,_UnixSelectorEventLoop.remove_signal_handlercCs6t|tstd||tkr2td|dS)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)
isinstanceintr7r9
valid_signalsr<r.rrrr8s
z$_UnixSelectorEventLoop._check_signalcCst|||||Sr)_UnixReadPipeTransportrpipeprotocolwaiterextrarrr_make_read_pipe_transportsz0_UnixSelectorEventLoop._make_read_pipe_transportcCst|||||Sr)_UnixWritePipeTransportrSrrr_make_write_pipe_transportsz1_UnixSelectorEventLoop._make_write_pipe_transportc	

st}
|
std|}t||||||||f||d|	}|
||j|z|IdHWnDt	t
fk
rYn,tk
r||
IdHYnXW5QRX|S)NzRasyncio.get_child_watcher() is not activated, subprocess support is not installed.)rVrW)rget_child_watcher	is_activer>
create_future_UnixSubprocessTransportadd_child_handlerZget_pid_child_watcher_callback
SystemExitKeyboardInterrupt
BaseExceptionr%Z_wait)
rrUrEshellstdinstdoutstderrbufsizerWkwargswatcherrVtransprrr_make_subprocess_transports8


z1_UnixSelectorEventLoop._make_subprocess_transportcCs||j|dSr)call_soon_threadsafeZ_process_exited)rpid
returncoderkrrrr`sz._UnixSelectorEventLoop._child_watcher_callback)sslsockserver_hostnamessl_handshake_timeoutc	s
|r|dkr6tdn |dk	r&td|dk	r6td|dk	r|dk	rNtdt|}ttjtjd}z |d|||IdHWq|YqXn@|dkrtd|j	tjks|j
tjkrtd||d|j|||||d	IdH\}}||fS)
Nz/you have to pass server_hostname when using sslz+server_hostname is only meaningful with ssl1ssl_handshake_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 )rs)r<osfspathsocketAF_UNIXSOCK_STREAMsetblockingZsock_connectr%familytypeZ_create_connection_transport)	rprotocol_factorypathrprqrrrs	transportrUrrrcreate_unix_connectionsR




z-_UnixSelectorEventLoop.create_unix_connectiondT)rqbacklogrprs
start_servingc
st|trtd|dk	r&|s&td|dk	rH|dk	r@tdt|}ttjtj}|ddkrz t	
t	|jrt|WnBt
k
rYn0tk
r}ztd||W5d}~XYnXz||Wnltk
r0}	z8||	jtjkrd|d}
ttj|
dnW5d}	~	XYn|YnXn<|dkrZtd	|jtjksv|jtjkrtd
||dt||g||||}|r|tjd|dIdH|S)
Nz*ssl argument must be an SSLContext or Nonertrur)rz2Unable to check or remove stale UNIX socket %r: %rzAddress z is already in usez-path was not specified, and no sock specifiedrvF)loop)rOboolr7r<rwrxryrzr{statS_ISSOCKst_moderemoveFileNotFoundErrorr=r
errorZbindr%rBZ
EADDRINUSEr}r~r|rZServerZ_start_servingrsleep)rrrrqrrprsrerrrFmsgZserverrrrcreate_unix_serversn






z)_UnixSelectorEventLoop.create_unix_serverc
sz
tjWn,tk
r6}ztdW5d}~XYnXz|}Wn2ttjfk
rv}ztdW5d}~XYnXzt|j	}Wn,t
k
r}ztdW5d}~XYnX|r|n|}	|	sdS|}
||
d|||||	d|
IdHS)Nzos.sendfile() is not availableznot a regular filer)
rwsendfileAttributeErrorrSendfileNotAvailableErrorr;ioUnsupportedOperationfstatst_sizer=r]_sock_sendfile_native_impl)rrqfileoffsetcountrFr;rZfsize	blocksizefutrrr_sock_sendfile_nativeJs2
z,_UnixSelectorEventLoop._sock_sendfile_nativec	Cs,|}	|dk	r|||r4||||dS|rd||}|dkrd||||||dSzt|	|||}
WnDttfk
r|dkr|	|||
|	|j||	||||||
Ynbtk
rj}z|dk	r|j
t
jkrt|tk	rtdt
j}||_|}|dkrBtd}
||||||
n||||||W5d}~XYnttfk
rYntk
r}z||||||W5d}~XYnjX|
dkr||||||nD||
7}||
7}|dkr
|	|||
|	|j||	||||||
dS)Nrzsocket is not connectedzos.sendfile call failed)r;
remove_writer	cancelled_sock_sendfile_update_fileposZ
set_resultrwrBlockingIOErrorInterruptedError_sock_add_cancellation_callbackZ
add_writerrr=rBZENOTCONNr~ConnectionError	__cause__rrZ
set_exceptionrarbrc)rrZ
registered_fdrqr;rrr
total_sentfdZsentrFnew_excrrrrras








z1_UnixSelectorEventLoop._sock_sendfile_native_implcCs|dkrt||tjdSNr)rwlseekSEEK_SET)rr;rrrrrrsz4_UnixSelectorEventLoop._sock_sendfile_update_fileposcsfdd}||dS)Ncs&|r"}|dkr"|dS)Nr3)rr;r)rrrrqrrcbszB_UnixSelectorEventLoop._sock_add_cancellation_callback.<locals>.cb)Zadd_done_callback)rrrqrrrrrsz6_UnixSelectorEventLoop._sock_add_cancellation_callback)N)NN)NN)N)N)N)__name__
__module____qualname____doc__rr%r2rHr0r)r8rXrZrlr`rrrrrr
__classcell__rrr!rr/sH-
 


.CFrcseZdZdZdfdd	ZddZddZd	d
ZddZd
dZ	ddZ
ddZddZe
jfddZdddZddZddZZS) rRiNcst|||jd<||_||_||_||_d|_d|_	t
|jj}t
|st
|st
|sd|_d|_d|_tdt
|jd|j|jj||j|jj|j|j|dk	r|jtj|ddS)NrTFz)Pipe transport is for pipes/sockets only.)rr_extra_loop_piper;_fileno	_protocol_closing_pausedrwrrrS_ISFIFOrS_ISCHRr<set_blocking	call_soonconnection_made_add_reader_read_readyr	_set_result_unless_cancelled)rrrTrUrVrWmoder!rrrs:



z_UnixReadPipeTransport.__init__cCs|jjg}|jdkr |dn|jr0|d|d|jt|jdd}|jdk	r|dk	rt	||jt
j}|r|dq|dn |jdk	r|dn
|ddd	
|S)
Nclosedclosingfd=	_selectorpollingidleopen<{}> )r"rrappendrrgetattrrr
_test_selector_event	selectorsZ
EVENT_READformatjoin)rrAr rrrr__repr__s(




z_UnixReadPipeTransport.__repr__c
Cszt|j|j}WnDttfk
r,Yntk
rX}z||dW5d}~XYn^X|rl|j	|nJ|j
rt
d|d|_|j
|j|j
|jj|j
|jddS)Nz"Fatal read error on pipe transport%r was closed by peerT)rwreadrmax_sizerrr=_fatal_errorrZ
data_receivedr	get_debugr
rAr_remove_readerrZeof_received_call_connection_lost)rr1rFrrrrs
z"_UnixReadPipeTransport._read_readycCs>|js|jrdSd|_|j|j|jr:td|dS)NTz%r pauses reading)rrrrrrr
debugrrrr
pause_readings
z$_UnixReadPipeTransport.pause_readingcCsB|js|jsdSd|_|j|j|j|jr>td|dS)NFz%r resumes reading)	rrrrrrrr
rrrrrresume_readings
z%_UnixReadPipeTransport.resume_readingcCs
||_dSrrrrUrrrset_protocol
sz#_UnixReadPipeTransport.set_protocolcCs|jSrrrrrrget_protocolsz#_UnixReadPipeTransport.get_protocolcCs|jSrrrrrr
is_closingsz!_UnixReadPipeTransport.is_closingcCs|js|ddSr)r_closerrrrr%sz_UnixReadPipeTransport.closecCs,|jdk	r(|d|t|d|jdSNzunclosed transport r#rr,r%r_warnrrr__del__s
z_UnixReadPipeTransport.__del__Fatal error on pipe transportcCsZt|tr4|jtjkr4|jrLtjd||ddn|j||||j	d|
|dSNz%r: %sTexc_info)message	exceptionrrU)rOr=rBZEIOrrr
rcall_exception_handlerrrrrFrrrrrs
z#_UnixReadPipeTransport._fatal_errorcCs(d|_|j|j|j|j|dSNT)rrrrrrrrFrrrr-sz_UnixReadPipeTransport._closecCs4z|j|W5|jd|_d|_d|_XdSrrr%rrZconnection_lostrrrrr2s
z,_UnixReadPipeTransport._call_connection_lost)NN)r)rrrrrrrrrrrrr%r*r+rrrrrrrr!rrRs
rRcseZdZd%fdd	ZddZddZdd	Zd
dZdd
ZddZ	ddZ
ddZddZddZ
ddZejfddZddZd&dd Zd'd!d"Zd#d$ZZS)(rYNc
st||||jd<||_||_||_t|_d|_	d|_
t|jj
}t|}t|}t|}	|s|s|	sd|_d|_d|_tdt|jd|j|jj||	s|rtjds|j|jj|j|j|dk	r|jtj|ddS)NrTrFz?Pipe transport is only for pipes, sockets and character devicesZaix)rrrrr;rr	bytearray_buffer
_conn_lostrrwrrrrrrr<rrrrr&platform
startswithrrr	r)
rrrTrUrVrWrZis_charZis_fifoZ	is_socketr!rrr?s:





z _UnixWritePipeTransport.__init__cCs|jjg}|jdkr |dn|jr0|d|d|jt|jdd}|jdk	r|dk	rt	||jt
j}|r|dn
|d|}|d|n |jdk	r|dn
|dd	
d
|S)Nrrrrrrzbufsize=rrr)r"rrrrrrrr
rrZEVENT_WRITEget_write_buffer_sizerr)rrAr rrhrrrrds,





z _UnixWritePipeTransport.__repr__cCs
t|jSr)lenrrrrrr|sz-_UnixWritePipeTransport.get_write_buffer_sizecCs6|jrtd||jr*|tn|dS)Nr)rrr
rArrBrokenPipeErrorrrrrrs

z#_UnixWritePipeTransport._read_readyc
Cs4t|trt|}|sdS|js&|jrN|jtjkr<td|jd7_dS|j	szt
|j|}Wntt
tfk
rd}YnZttfk
rYnBtk
r}z$|jd7_||dWYdSd}~XYnX|t|krdS|dkrt||d}|j|j|j|j	|7_	|dS)Nz=pipe closed by peer or os.write(pipe, data) raised exception.rr#Fatal write error on pipe transport)rOr
memoryviewrrrZ!LOG_THRESHOLD_FOR_CONNLOST_WRITESr
warningrrwwriterrrrarbrcrrrZ_add_writer_write_readyZ_maybe_pause_protocol)rr1nrFrrrrs6


z_UnixWritePipeTransport.writec
Cszt|j|j}Wnttfk
r,Ynttfk
rDYntk
r}z6|j	|j
d7_
|j|j|
|dW5d}~XYnfX|t|jkr|j	|j|j||jr|j|j|ddS|dkr|jd|=dS)Nrrr)rwrrrrrrarbrcr-rr_remove_writerrrZ_maybe_resume_protocolrrr)rrrFrrrrs*


z$_UnixWritePipeTransport._write_readycCsdSrrrrrr
can_write_eofsz%_UnixWritePipeTransport.can_write_eofcCs8|jr
dSd|_|js4|j|j|j|jddSr)rrrrrrrrrrr	write_eofsz!_UnixWritePipeTransport.write_eofcCs
||_dSrrrrrrrsz$_UnixWritePipeTransport.set_protocolcCs|jSrrrrrrrsz$_UnixWritePipeTransport.get_protocolcCs|jSrrrrrrrsz"_UnixWritePipeTransport.is_closingcCs|jdk	r|js|dSr)rrrrrrrr%sz_UnixWritePipeTransport.closecCs,|jdk	r(|d|t|d|jdSrrrrrrrs
z_UnixWritePipeTransport.__del__cCs|ddSr)rrrrrabortsz_UnixWritePipeTransport.abortrcCsNt|tr(|jr@tjd||ddn|j||||jd||dSr)	rOr=rrr
rrrrrrrrrs

z$_UnixWritePipeTransport._fatal_errorcCsFd|_|jr|j|j|j|j|j|j|j|dSr)	rrrrrr-rrrrrrrrs
z_UnixWritePipeTransport._closecCs4z|j|W5|jd|_d|_d|_XdSrrrrrrrs
z-_UnixWritePipeTransport._call_connection_lost)NN)r)N)rrrrrrrrrrrrrrr%r*r+rr	rrrrrrr!rrY<s"%	#	

rYc@seZdZddZdS)r^c		Ksd}|tjkrt\}}zPtj|f||||d|d||_|dk	rh|t|d|d|j_	d}W5|dk	r||XdS)NF)rdrerfrgZuniversal_newlinesrhwb)	buffering)

subprocessPIPEryZ
socketpairr%Popen_procrdetachre)	rrErdrerfrgrhriZstdin_wrrr_starts.
z_UnixSubprocessTransport._startN)rrrrrrrrr^	sr^c@sHeZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
dS)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.
    cGs
tdS)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.
        NNotImplementedErrorrrnrDrErrrr_9s	z&AbstractChildWatcher.add_child_handlercCs
tdS)zRemoves the handler for process 'pid'.

        The function returns True if the handler was successfully removed,
        False if there was nothing to remove.Nrrrnrrrremove_child_handlerDsz)AbstractChildWatcher.remove_child_handlercCs
tdS)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.
        Nrrrrrrattach_loopLsz AbstractChildWatcher.attach_loopcCs
tdS)zlClose the watcher.

        This must be called to make sure that any underlying resource is freed.
        Nrrrrrr%VszAbstractChildWatcher.closecCs
tdS)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.

        Nrrrrrr\]szAbstractChildWatcher.is_activecCs
tdS)zdEnter the watcher's context and allow starting new processes

        This function must return selfNrrrrr	__enter__fszAbstractChildWatcher.__enter__cCs
tdS)zExit the watcher's contextNrrabcrrr__exit__lszAbstractChildWatcher.__exit__N)rrrrr_rrr%r\rrrrrrr"s
	rcCs2t|rt|St|r*t|S|SdSr)rwWIFSIGNALEDWTERMSIG	WIFEXITEDWEXITSTATUS)statusrrr_compute_returncodeqs



r$c@sDeZdZddZddZddZddZd	d
ZddZd
dZ	dS)BaseChildWatchercCsd|_i|_dSr)r
_callbacksrrrrrszBaseChildWatcher.__init__cCs|ddSr)rrrrrr%szBaseChildWatcher.closecCs|jdk	o|jSr)rZ
is_runningrrrrr\szBaseChildWatcher.is_activecCs
tdSrr)rexpected_pidrrr_do_waitpidszBaseChildWatcher._do_waitpidcCs
tdSrrrrrr_do_waitpid_allsz BaseChildWatcher._do_waitpid_allcCsf|jdk	r$|dkr$|jr$tdt|jdk	r<|jtj||_|dk	rb|tj|j	|
dS)NzCA loop is being detached from a child watcher with pending handlers)rr&r*r+RuntimeWarningr)r9SIGCHLDrH	_sig_chldr)rrrrrs
zBaseChildWatcher.attach_loopc
Cs^z|WnLttfk
r&Yn4tk
rX}z|jd|dW5d}~XYnXdS)N$Unknown exception in SIGCHLD handler)rr)r)rarbrcrrrrrrr,szBaseChildWatcher._sig_chldN)
rrrrr%r\r(r)rr,rrrrr%sr%csPeZdZdZfddZddZddZdd	Zd
dZdd
Z	ddZ
ZS)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)
    cs|jtdSr)r&r-rr%rr!rrr%s
zSafeChildWatcher.closecCs|SrrrrrrrszSafeChildWatcher.__enter__cCsdSrrrrrrrszSafeChildWatcher.__exit__cGs||f|j|<||dSr)r&r(rrrrr_sz"SafeChildWatcher.add_child_handlercCs*z|j|=WdStk
r$YdSXdSNTFr&rJrrrrrs
z%SafeChildWatcher.remove_child_handlercCst|jD]}||q
dSrr(r&r(rrrrr)sz SafeChildWatcher._do_waitpid_allcCszt|tj\}}Wn(tk
r>|}d}td|Yn.X|dkrLdSt|}|jrlt	d||z|j
|\}}Wn.tk
r|jrtjd|ddYnX|||f|dS)N8Unknown child process pid %d, will report returncode 255r$process %s exited with returncode %s'Child watcher got an unexpected pid: %rTr)
rwwaitpidWNOHANGChildProcessErrorr
rr$rrrr&poprJ)rr'rnr#rorDrErrrr(s4


zSafeChildWatcher._do_waitpid)rrrrr%rrr_rr)r(rrrr!rrs
rcsTeZdZdZfddZfddZddZdd	Zd
dZdd
Z	ddZ
ZS)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).
    cs$tt|_i|_d|_dSr)rr	threadingZLock_lock_zombies_forksrr!rrrs

zFastChildWatcher.__init__cs"|j|jtdSr)r&r-r;rr%rr!rrr%s

zFastChildWatcher.closec
Cs0|j |jd7_|W5QRSQRXdS)Nr)r:r<rrrrrszFastChildWatcher.__enter__c	Cs^|jB|jd8_|js"|js0W5QRdSt|j}|jW5QRXtd|dS)Nrz5Caught subprocesses termination from unknown pids: %s)r:r<r;r?r-r
r)rrrrZcollateral_victimsrrrrs
zFastChildWatcher.__exit__c	Gsf|jFz|j|}Wn.tk
rF||f|j|<YW5QRdSXW5QRX|||f|dSr)r:r;r8rJr&)rrnrDrErorrrr_'sz"FastChildWatcher.add_child_handlercCs*z|j|=WdStk
r$YdSXdSr.r/rrrrr5s
z%FastChildWatcher.remove_child_handlerc	Csztdtj\}}Wntk
r,YdSX|dkr:dSt|}|jz|j|\}}WnNtk
r|j	r||j
|<|jrt
d||YW5QRqd}YnX|jrt
d||W5QRX|dkrt
d||q|||f|qdS)Nr3rz,unknown process %s exited with returncode %sr3z8Caught subprocess termination from unknown pid: %d -> %d)rwr5r6r7r$r:r&r8rJr<r;rrr
rr)rrnr#rorDrErrrr)<s@



z FastChildWatcher._do_waitpid_all)rrrrrr%rrr_rr)rrrr!rrs	rc@sheZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZddZddZ
ddZdS)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).
    cCsi|_d|_dSr)r&_saved_sighandlerrrrrrzszMultiLoopChildWatcher.__init__cCs
|jdk	Sr)r=rrrrr\~szMultiLoopChildWatcher.is_activecCsT|j|jdkrdSttj}||jkr:tdnttj|jd|_dS)Nz+SIGCHLD handler was changed by outside code)	r&r-r=r9	getsignalr+r,r
r)rrNrrrr%s


zMultiLoopChildWatcher.closecCs|SrrrrrrrszMultiLoopChildWatcher.__enter__cCsdSrrrexc_typeZexc_valZexc_tbrrrrszMultiLoopChildWatcher.__exit__cGs&t}|||f|j|<||dSr)rget_running_loopr&r()rrnrDrErrrrr_sz'MultiLoopChildWatcher.add_child_handlercCs*z|j|=WdStk
r$YdSXdSr.r/rrrrrs
z*MultiLoopChildWatcher.remove_child_handlercCsN|jdk	rdSttj|j|_|jdkr<tdtj|_ttjddS)NzaPrevious SIGCHLD handler was set by non-Python code, restore to default handler on watcher close.F)r=r9r+r,r
rrMr@rrrrrs


z!MultiLoopChildWatcher.attach_loopcCst|jD]}||q
dSrr0rrrrr)sz%MultiLoopChildWatcher._do_waitpid_allc	Cszt|tj\}}Wn,tk
rB|}d}td|d}YnX|dkrPdSt|}d}z|j|\}}}Wn$t	k
rtjd|ddYnHX|
rtd||n.|r|rtd	|||j
|||f|dS)
Nr1r2FrTr4r%Loop %r that handles pid %r is closedr3)rwr5r6r7r
rr$r&r8rJ	is_closedrrrm)	rr'rnr#roZ	debug_logrrDrErrrr(s:
z!MultiLoopChildWatcher._do_waitpidc	CsLz|Wn:ttfk
r&Yn"tk
rFtjdddYnXdS)Nr-Tr)r)rarbrcr
r)rrrrrrr,szMultiLoopChildWatcher._sig_chldN)rrrrrr\r%rrr_rrr)r(r,rrrrrgs%rc@sneZdZdZddZddZddZdd	Zd
dZdd
Z	e
jfddZddZ
ddZddZddZdS)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.
    cCstd|_i|_dSr)	itertoolsr_pid_counter_threadsrrrrrszThreadedChildWatcher.__init__cCsdSrrrrrrr\szThreadedChildWatcher.is_activecCs|dSr)
_join_threadsrrrrr%szThreadedChildWatcher.closecCs.ddt|jD}|D]}|qdS)z%Internal: Join all non-daemon threadscSsg|]}|r|js|qSr)is_alivedaemon.0threadrrr
<listcomp>sz6ThreadedChildWatcher._join_threads.<locals>.<listcomp>N)r(rFvaluesr)rthreadsrLrrrrGsz"ThreadedChildWatcher._join_threadscCs|SrrrrrrrszThreadedChildWatcher.__enter__cCsdSrrr?rrrrszThreadedChildWatcher.__exit__cCs6ddt|jD}|r2||jdt|ddS)NcSsg|]}|r|qSr)rHrJrrrrM	sz0ThreadedChildWatcher.__del__.<locals>.<listcomp>z0 has registered but not finished child processesr#)r(rFrNr"r,)rrrOrrrrszThreadedChildWatcher.__del__cGsFt}tj|jdt|j||||fdd}||j|<|dS)Nzwaitpid-T)targetnamerErI)	rrAr9ZThreadr(nextrErFstart)rrnrDrErrLrrrr_s

z&ThreadedChildWatcher.add_child_handlercCsdSrrrrrrrsz)ThreadedChildWatcher.remove_child_handlercCsdSrrrrrrrsz ThreadedChildWatcher.attach_loopcCszt|d\}}Wn(tk
r<|}d}td|Yn Xt|}|r\td|||rttd||n|j	|||f||j
|dS)Nrr1r2r3rB)rwr5r7r
rr$rrrCrmrFr8)rrr'rDrErnr#rorrrr("s&
z ThreadedChildWatcher._do_waitpidN)rrrrrr\r%rGrrr*r+rr_rrr(rrrrrs	rcsHeZdZdZeZfddZddZfddZdd	Z	d
dZ
ZS)_UnixDefaultEventLoopPolicyz:UNIX event loop policy with a watcher for child processes.cstd|_dSr)rr_watcherrr!rrrAs
z$_UnixDefaultEventLoopPolicy.__init__c	CsHtj8|jdkr:t|_tttjr:|j|j	j
W5QRXdSr)rr:rUrrOr9current_thread_MainThreadr_localrrrrr
_init_watcherEs
z)_UnixDefaultEventLoopPolicy._init_watchercs6t||jdk	r2tttjr2|j|dS)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)rset_event_looprUrOr9rVrWrrr!rrrZMs

z*_UnixDefaultEventLoopPolicy.set_event_loopcCs|jdkr||jS)z~Get the watcher for child processes.

        If not yet set, a ThreadedChildWatcher object is automatically created.
        N)rUrYrrrrr[[s
z-_UnixDefaultEventLoopPolicy.get_child_watchercCs|jdk	r|j||_dS)z$Set the watcher for child processes.N)rUr%)rrjrrrset_child_watcheres

z-_UnixDefaultEventLoopPolicy.set_child_watcher)rrrrrZ
_loop_factoryrrYrZr[r[rrrr!rrT=s
rT)2rrBrrDrwrr9ryrrr&r9r*rrrrrrr	r
rrlogr
__all__rImportErrorrZBaseSelectorEventLooprZ
ReadTransportrRZ_FlowControlMixinZWriteTransportrYZBaseSubprocessTransportr^rr$r%rrrrZBaseDefaultEventLoopPolicyrTrrrrrr<module>s`	
	NO5Ji}Y3

T1KUS90T
  root-grov@89.117.188.241:~$