JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrJFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrB  f؟@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZddl mZddl mZddl mZdd l mZdd l mZdd l mZdd l mZdd lmZdZe jdkredddZGdddejZGdddejZGdddej ej!Z"Gdddej#Z$GdddZ%Gddde%Z&Gdd d e&Z'Gd!d"d"e&Z(Gd#d$d$ej)Z*eZ+e*Z,dS)%z2Selector event loop for Unix with signal handling.N) base_events)base_subprocess) constants) coroutines)events)futures)selector_events)tasks) transports)logger)SelectorEventLoopAbstractChildWatcherSafeChildWatcherFastChildWatcherDefaultEventLoopPolicyZwin32z+Signals are not really supported on WindowscCsdS)zDummy signal handler.N)signumframerr8/opt/alt/python37/lib64/python3.7/asyncio/unix_events.py_sighandler_noop'srcseZdZdZd)fdd ZfddZddZd d Zd d Zd dZ ddZ d*ddZ d+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|_dS)N)super__init___signal_handlers)selfselector) __class__rrr2s z_UnixSelectorEventLoop.__init__cs^tts2xFt|jD]}||qWn(|jrZtjd|dt |d|j dS)NzClosing the loop z@ on interpreter shutdown stage, skipping signal handlers removal)source) rclosesys is_finalizinglistrremove_signal_handlerwarningswarnResourceWarningclear)rsig)rrrr6s z_UnixSelectorEventLoop.closecCs"x|D]}|sq||qWdS)N)_handle_signal)rdatarrrr_process_self_dataDs z)_UnixSelectorEventLoop._process_self_datac GsLt|st|rtd|||yt|j Wn2t t fk rt}zt t |Wdd}~XYnXt|||d}||j|<yt|tt|dWnt k rF}zz|j|=|jsytdWn4t t fk r}ztd|Wdd}~XYnX|jtjkr4t d|dnWdd}~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()NFzset_wakeup_fd(-1) failed: %szsig z cannot be caught)rZ iscoroutineZiscoroutinefunction TypeError _check_signalZ _check_closedsignal set_wakeup_fdZ_csockfileno ValueErrorOSError RuntimeErrorstrrZHandlerr siginterruptr infoerrnoEINVAL)rr(callbackargsexchandleZnexcrrradd_signal_handlerKs0     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(r=rrrr)xs   z%_UnixSelectorEventLoop._handle_signalc Cs||y |j|=Wntk r*dSX|tjkr>tj}ntj}yt||WnBtk r}z$|jtj krt d|dnWdd}~XYnX|jsyt dWn2t tfk r}zt d|Wdd}~XYnXdS)zwRemove a handler for a signal. UNIX only. Return True if a signal handler was removed, False if not. Fzsig z cannot be caughtNr,zset_wakeup_fd(-1) failed: %sT)r.rKeyErrorr/SIGINTdefault_int_handlerSIG_DFLr3r8r9r4r0r2r r7)rr(Zhandlerr<rrrr#s(    z,_UnixSelectorEventLoop.remove_signal_handlercCsLt|tstd|d|kr.tjksHntd|dtjddS)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 rzsig z out of range(1, )N) isinstanceintr-r/NSIGr2)rr(rrrr.s z$_UnixSelectorEventLoop._check_signalcCst|||||S)N)_UnixReadPipeTransport)rpipeprotocolwaiterextrarrr_make_read_pipe_transportsz0_UnixSelectorEventLoop._make_read_pipe_transportcCst|||||S)N)_UnixWritePipeTransport)rrIrJrKrLrrr_make_write_pipe_transportsz1_UnixSelectorEventLoop._make_write_pipe_transportc st} |} t||||||||f| |d| } | | |j| y| IdHWn,tk r| | IdHYnXWdQRX| S)N)rKrL) rget_child_watcher create_future_UnixSubprocessTransportadd_child_handlerZget_pid_child_watcher_callback ExceptionrZ_wait) rrJr;shellstdinstdoutstderrbufsizerLkwargswatcherrKtransprrr_make_subprocess_transports     z1_UnixSelectorEventLoop._make_subprocess_transportcCs||j|dS)N)Zcall_soon_threadsafeZ_process_exited)rpid returncoder]rrrrTsz._UnixSelectorEventLoop._child_watcher_callback)sslsockserver_hostnamessl_handshake_timeoutc s |dkst|tst|r,|dkrLtdn |dk rs(     z,_UnixSelectorEventLoop._sock_sendfile_nativec Cs|} |dk r|||r4||||dS|rd||}|dkrd||||||dSyt| |||} Wn*ttfk r|dkr| ||| | |j || |||||| YnHt k rj} z|dk r| j t jkrt| tk rtdt j} | | _| } |dkrBtd} |||||| n|||||| Wdd} ~ XYntk r} z|||||| Wdd} ~ XYnjX| dkr||||||nD|| 7}|| 7}|dkr| ||| | |j || |||||| dS)Nrzsocket is not connectedzos.sendfile call failed)r1 remove_writer cancelled_sock_sendfile_update_fileposZ set_resultrfrBlockingIOErrorInterruptedError_sock_add_cancellation_callbackZ add_writerrr3r8ZENOTCONNrmConnectionError __cause__rrZ set_exceptionrU)rrZ registered_fdrbr1rrr total_sentfdZsentr<new_excr~rrrrUs`             z1_UnixSelectorEventLoop._sock_sendfile_native_implcCs|dkrt||tjdS)Nr)rflseekSEEK_SET)rr1rrrrrrsz4_UnixSelectorEventLoop._sock_sendfile_update_fileposcsfdd}||dS)Ncs&|r"}|dkr"|dS)Nr,)rr1r)rr)rrbrrcbszB_UnixSelectorEventLoop._sock_add_cancellation_callback..cb)Zadd_done_callback)rrrbrr)rrbrrsz6_UnixSelectorEventLoop._sock_add_cancellation_callback)N)NN)NN)N)N)N)__name__ __module__ __qualname____doc__rrr+r>r)r#r.rMrOr^rTrqrrrrr __classcell__rr)rrr,s4 -      *?DrcseZdZdZdfdd ZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ dddZddZddZZS) rHiNcst|||jd<||_||_||_||_d|_d|_ t |jj }t |st |st |sd|_d|_d|_tdt |jd|j|jj||j|jj|j|j|dk r|jtj|ddS)NrIFz)Pipe transport is for pipes/sockets only.)rr_extra_loop_piper1_fileno _protocol_closing_pausedrfrrzrxS_ISFIFOryS_ISCHRr2 set_blocking call_soonconnection_made _add_reader _read_readyr_set_result_unless_cancelled)rrvrIrJrKrLmode)rrrrs.         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) Nclosedclosingzfd= _selectorpollingidleopenz<{}> )rrrappendrrgetattrrr _test_selector_event selectorsZ EVENT_READformatjoin)rr7rrrrr__repr__s"         z_UnixReadPipeTransport.__repr__c Csyt|j|j}WnDttfk r,Yntk rX}z||dWdd}~XYn^X|rl|j |nJ|j rt d|d|_|j |j|j |jj|j |jddS)Nz"Fatal read error on pipe transportz%r was closed by peerT)rfreadrmax_sizerrr3 _fatal_errorrZ data_receivedr get_debugr r7r_remove_readerrZ eof_received_call_connection_lost)rr*r<rrrrs  z"_UnixReadPipeTransport._read_readycCs>|js |jrdSd|_|j|j|jr:td|dS)NTz%r pauses reading)rrrrrrr debug)rrrr pause_readings   z$_UnixReadPipeTransport.pause_readingcCsB|js |jsdSd|_|j|j|j|jr>td|dS)NFz%r resumes reading) rrrrrrrr r)rrrrresume_readings   z%_UnixReadPipeTransport.resume_readingcCs ||_dS)N)r)rrJrrr set_protocolsz#_UnixReadPipeTransport.set_protocolcCs|jS)N)r)rrrr get_protocolsz#_UnixReadPipeTransport.get_protocolcCs|jS)N)r)rrrr is_closingsz!_UnixReadPipeTransport.is_closingcCs|js|ddS)N)r_close)rrrrrsz_UnixReadPipeTransport.closecCs.|jdk r*tjd|t|d|jdS)Nzunclosed transport )r)rr$r%r&r)rrrr__del__ s z_UnixReadPipeTransport.__del__Fatal error on pipe transportcCsZt|tr4|jtjkr4|jrLtjd||ddn|j||||j d| |dS)Nz%r: %sT)exc_info)message exceptionrprJ) rEr3r8ZEIOrrr rcall_exception_handlerrr)rr<rrrrrs  z#_UnixReadPipeTransport._fatal_errorcCs(d|_|j|j|j|j|dS)NT)rrrrrr)rr<rrrr sz_UnixReadPipeTransport._closecCs4z|j|Wd|jd|_d|_d|_XdS)N)rconnection_lostrrr)rr<rrrr%s  z,_UnixReadPipeTransport._call_connection_lost)NN)r)rrrrrrrrrrrrrrrrrrrr)rrrHs rHcseZdZd%fdd ZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZd&dd Zd'd!d"Zd#d$ZZS)(rNNc 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)NrIrFz?Pipe transport is only for pipes, sockets and character devicesZaix)rrrrr1rr bytearray_buffer _conn_lostrrfrrzrxrrryr2rrrrr platform startswithrrrr) rrvrIrJrKrLrZis_charZis_fifoZ is_socket)rrrr2s2         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) Nrrzfd=rrrzbufsize=rz<{}>r)rrrrrrrrr rrZ EVENT_WRITEget_write_buffer_sizerr)rr7rrrZrrrrWs&         z _UnixWritePipeTransport.__repr__cCs t|jS)N)lenr)rrrrrosz-_UnixWritePipeTransport.get_write_buffer_sizecCs6|jrtd||jr*|tn|dS)Nz%r was closed by peer)rrr r7rrBrokenPipeError)rrrrrrs   z#_UnixWritePipeTransport._read_readyc Cs2t|tttfstt|t|tr.t|}|s6dS|jsB|jrj|jtj krXt d|jd7_dS|j syt |j|}WnVttfk rd}Yn<tk r}z|jd7_||ddSd}~XYnX|t|krdS|dkrt||d}|j|j|j|j |7_ |dS)Nz=pipe closed by peer or os.write(pipe, data) raised exception.rrz#Fatal write error on pipe transport)rEbytesr memoryviewrereprrrrZ!LOG_THRESHOLD_FOR_CONNLOST_WRITESr warningrrfwriterrrrUrrrZ _add_writer _write_readyZ_maybe_pause_protocol)rr*nr<rrrr{s4       z_UnixWritePipeTransport.writec Cs|jstdyt|j|j}Wnjttfk r:Yntk r}z6|j|j d7_ |j |j| |dWdd}~XYnfX|t |jkr|j|j |j||jr|j |j|ddS|dkr|jd|=dS)NzData should not be emptyrz#Fatal write error on pipe transportr)rrerfrrrrrUr'rr_remove_writerrrZ_maybe_resume_protocolrrr)rrr<rrrrs(   z$_UnixWritePipeTransport._write_readycCsdS)NTr)rrrr can_write_eofsz%_UnixWritePipeTransport.can_write_eofcCsB|jr dS|jstd|_|js>|j|j|j|jddS)NT) rrrerrrrrr)rrrr write_eofs z!_UnixWritePipeTransport.write_eofcCs ||_dS)N)r)rrJrrrrsz$_UnixWritePipeTransport.set_protocolcCs|jS)N)r)rrrrrsz$_UnixWritePipeTransport.get_protocolcCs|jS)N)r)rrrrrsz"_UnixWritePipeTransport.is_closingcCs|jdk r|js|dS)N)rrr)rrrrrsz_UnixWritePipeTransport.closecCs.|jdk r*tjd|t|d|jdS)Nzunclosed transport )r)rr$r%r&r)rrrrrs z_UnixWritePipeTransport.__del__cCs|ddS)N)r)rrrrabortsz_UnixWritePipeTransport.abortFatal error on pipe transportcCsNt|tr(|jr@tjd||ddn|j||||jd||dS)Nz%r: %sT)r)rrrprJ) rEr3rrr rrrr)rr<rrrrrs   z$_UnixWritePipeTransport._fatal_errorcCsFd|_|jr|j|j|j|j|j|j|j|dS)NT) rrrrrr'rrr)rr<rrrrs  z_UnixWritePipeTransport._closecCs4z|j|Wd|jd|_d|_d|_XdS)N)rrrrr)rr<rrrrs  z-_UnixWritePipeTransport._call_connection_lost)NN)r)N)rrrrrrrrrrrrrrrrrrrrrrr)rrrN/s"% !   rNc@seZdZddZdS)rRc Ksd}|tjkrt\}}zPtj|f||||d|d||_|dk rh|t|d|d|j_ d}Wd|dk r||XdS)NF)rVrWrXrYZuniversal_newlinesrZwb) buffering) subprocessPIPErhZ socketpairPopen_procrrdetachrW) rr;rVrWrXrYrZr[Zstdin_wrrr_starts   z_UnixSubprocessTransport._startN)rrrrrrrrrRsrRc@s@eZdZdZddZddZddZdd Zd d Zd d Z 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. N)NotImplementedError)rr_r:r;rrrrS)s 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.N)r)rr_rrrremove_child_handler4sz)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. N)r)rrvrrr attach_loop<sz AbstractChildWatcher.attach_loopcCs tdS)zlClose the watcher. This must be called to make sure that any underlying resource is freed. N)r)rrrrrFszAbstractChildWatcher.closecCs tdS)zdEnter the watcher's context and allow starting new processes This function must return selfN)r)rrrr __enter__MszAbstractChildWatcher.__enter__cCs tdS)zExit the watcher's contextN)r)rabcrrr__exit__SszAbstractChildWatcher.__exit__N) rrrrrSrrrrrrrrrrs  rc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)BaseChildWatchercCsd|_i|_dS)N)r _callbacks)rrrrrZszBaseChildWatcher.__init__cCs|ddS)N)r)rrrrr^szBaseChildWatcher.closecCs tdS)N)r)r expected_pidrrr _do_waitpidaszBaseChildWatcher._do_waitpidcCs tdS)N)r)rrrr_do_waitpid_alldsz BaseChildWatcher._do_waitpid_allcCs~|dkst|tjst|jdk r<|dkr<|jr _sig_chldr)rrvrrrrgs zBaseChildWatcher.attach_loopc CsFy |Wn4tk r@}z|jd|dWdd}~XYnXdS)Nz$Unknown exception in SIGCHLD handler)rr)rrUrr)rr<rrrr{s  zBaseChildWatcher._sig_chldcCs2t|rt| St|r*t|S|SdS)N)rf WIFSIGNALEDWTERMSIG WIFEXITED WEXITSTATUS)rstatusrrr_compute_returncodes     z$BaseChildWatcher._compute_returncodeN) rrrrrrrrrrrrrrrXs rcsPeZdZdZfddZddZddZdd Zd d Zd d Z ddZ Z 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) cs|jtdS)N)rr'rr)r)rrrrs zSafeChildWatcher.closecCs|S)Nr)rrrrrszSafeChildWatcher.__enter__cCsdS)Nr)rrrrrrrrszSafeChildWatcher.__exit__cGs.|jdkrtd||f|j|<||dS)NzICannot add child handler, the child watcher does not have a loop attached)rr4rr)rr_r:r;rrrrSs  z"SafeChildWatcher.add_child_handlercCs&y |j|=dStk r dSXdS)NTF)rr@)rr_rrrrs z%SafeChildWatcher.remove_child_handlercCs"xt|jD]}||q WdS)N)r"rr)rr_rrrrsz SafeChildWatcher._do_waitpid_allcCs|dks tyt|tj\}}Wn(tk rJ|}d}td|Yn0X|dkrXdS||}|j rzt d||y|j |\}}Wn.t k r|j rtjd|ddYnX|||f|dS)Nrz8Unknown child process pid %d, will report returncode 255z$process %s exited with returncode %sz'Child watcher got an unexpected pid: %rT)r)rerfwaitpidWNOHANGChildProcessErrorr rrrrrrpopr@)rrr_rr`r:r;rrrrs,     zSafeChildWatcher._do_waitpid) rrrrrrrrSrrrrrr)rrrs   rcsTeZdZdZfddZfddZddZdd Zd d Zd d Z ddZ Z S)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|_dS)Nr)rr threadingZLock_lock_zombies_forks)r)rrrrs  zFastChildWatcher.__init__cs"|j|jtdS)N)rr'r rr)r)rrrrs  zFastChildWatcher.closec Cs$|j|jd7_|SQRXdS)Nr)r r)rrrrrszFastChildWatcher.__enter__c CsT|j8|jd8_|js"|js&dSt|j}|jWdQRXtd|dS)Nrz5Caught subprocesses termination from unknown pids: %s)r rr r5r'r r)rrrrZcollateral_victimsrrrrs  zFastChildWatcher.__exit__c Gsz|jstd|jdkr td|j:y|j|}Wn"tk rZ||f|j|<dSXWdQRX|||f|dS)NzMust use the context managerzICannot add child handler, the child watcher does not have a loop attached) rrerr4r r r r@r)rr_r:r;r`rrrrS s z"FastChildWatcher.add_child_handlercCs&y |j|=dStk r dSXdS)NTF)rr@)rr_rrrr s z%FastChildWatcher.remove_child_handlerc Csxytdtj\}}Wntk r,dSX|dkr:dS||}|jvy|j|\}}WnBtk r|j r||j |<|j rt d||wd}YnX|j rt d||WdQRX|dkrt d||q|||f|qWdS)Nr,rz,unknown process %s exited with returncode %sz$process %s exited with returncode %sz8Caught subprocess termination from unknown pid: %d -> %d)rfrrr rr rr r@rr rrr rr)rr_rr`r:r;rrrr's6      z FastChildWatcher._do_waitpid_all) rrrrrrrrrSrrrrr)rrrs   rcsHeZdZdZeZfddZddZfddZdd Z d d Z Z S) _UnixDefaultEventLoopPolicyz:UNIX event loop policy with a watcher for child processes.cstd|_dS)N)rr_watcher)r)rrrrVs z$_UnixDefaultEventLoopPolicy.__init__c CsHtj8|jdkr:t|_tttjr:|j|j j WdQRXdS)N) rr rrrEr current_thread _MainThreadr_localr)rrrr _init_watcherZs  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_looprrEr rrr)rrv)rrrrbs  z*_UnixDefaultEventLoopPolicy.set_event_loopcCs|jdkr||jS)zzGet the watcher for child processes. If not yet set, a SafeChildWatcher object is automatically created. N)rr)rrrrrPps z-_UnixDefaultEventLoopPolicy.get_child_watchercCs4|dkst|tst|jdk r*|j||_dS)z$Set the watcher for child processes.N)rErrerr)rr\rrrset_child_watcherzs  z-_UnixDefaultEventLoopPolicy.set_child_watcher) rrrrrZ _loop_factoryrrrrPrrrr)rrrRs   r)-rr8rrfrr/rhrxrr r r$rrrrrrr r r logr __all__r ImportErrorrZBaseSelectorEventLooprZ ReadTransportrHZ_FlowControlMixinZWriteTransportrNZBaseSubprocessTransportrRrrrrZBaseDefaultEventLoopPolicyrr rrrrrsR           | JF=On3