3 \#@sddlZddlZddlZddlmZddlmZddlmZddlmZddl m Z Gdd d ej Z Gd d d ej ZGd d d eejZdS)N)compat) protocols) transports) coroutine)loggercseZdZd0fdd ZddZddZdd Zd d Zd d ZddZ e j rTddZ ddZ ddZddZddZddZddZddZed d!Zd"d#Zd$d%Zd&d'Zd(d)Zed*d+Zd,d-Zd.d/ZZS)1BaseSubprocessTransportNc  s&tj| d|_||_||_d|_d|_d|_g|_t j |_ i|_ d|_ |tjkr`d|j d<|tjkrtd|j d<|tjkrd|j d<y"|jf||||||d| Wn|jYnX|jj|_|j|jd<|jjrt|ttfr|} n|d} tjd| |j|jj|j| dS)NFrr)argsshellstdinstdoutstderrbufsize subprocesszprocess %r created: pid %s)super__init___closed _protocol_loop_proc_pid _returncode _exit_waiters collectionsdeque_pending_calls_pipes _finishedrPIPE_startclosepidZ_extra get_debug isinstancebytesstrrdebugZ create_task_connect_pipes) selfloopprotocolr r r r rrwaiterZextrakwargsZprogram) __class__'/usr/lib64/python3.6/base_subprocess.pyrs@            z BaseSubprocessTransport.__init__cCs |jjg}|jr|jd|jdk r4|jd|j|jdk rP|jd|jn |jdk rf|jdn |jd|jjd}|dk r|jd|j|jjd}|jjd }|dk r||kr|jd |jn0|dk r|jd |j|dk r|jd |jd dj |S)Nclosedzpid=%sz returncode=%sZrunningz not startedrzstdin=%srr zstdout=stderr=%sz stdout=%sz stderr=%sz<%s> ) r.__name__rappendrrrgetpipejoin)r)infor r rr/r/r0__repr__9s,          z BaseSubprocessTransport.__repr__cKstdS)N)NotImplementedError)r)r r r r rrr-r/r/r0r VszBaseSubprocessTransport._startcCs ||_dS)N)r)r)r+r/r/r0 set_protocolYsz$BaseSubprocessTransport.set_protocolcCs|jS)N)r)r)r/r/r0 get_protocol\sz$BaseSubprocessTransport.get_protocolcCs|jS)N)r)r)r/r/r0 is_closing_sz"BaseSubprocessTransport.is_closingc Cs|jr dSd|_x&|jjD]}|dkr*q|jjqW|jdk r|jdkr|jjdkr|jj rpt j d|y|jj Wnt k rYnXdS)NTz$Close running child process: kill %r)rrvaluesr6r!rrZpollrr#rZwarningkillProcessLookupError)r)protor/r/r0r!bs     zBaseSubprocessTransport.closecCs&|js"tjd|t|d|jdS)Nzunclosed transport %r)source)rwarningswarnResourceWarningr!)r)r/r/r0__del__s zBaseSubprocessTransport.__del__cCs|jS)N)r)r)r/r/r0get_pidszBaseSubprocessTransport.get_pidcCs|jS)N)r)r)r/r/r0get_returncodesz&BaseSubprocessTransport.get_returncodecCs||jkr|j|jSdSdS)N)rr6)r)fdr/r/r0get_pipe_transports  z*BaseSubprocessTransport.get_pipe_transportcCs|jdkrtdS)N)rr@)r)r/r/r0 _check_procs z#BaseSubprocessTransport._check_proccCs|j|jj|dS)N)rKr send_signal)r)signalr/r/r0rLsz#BaseSubprocessTransport.send_signalcCs|j|jjdS)N)rKr terminate)r)r/r/r0rNsz!BaseSubprocessTransport.terminatecCs|j|jjdS)N)rKrr?)r)r/r/r0r?szBaseSubprocessTransport.killc #s^yj}j}|jdk rB|jfdd|jEdH\}}|jd<|jdk rv|jfdd|jEdH\}}|jd<|jdk r|jfdd|jEdH\}}|jd<jdk st |j j j x"jD]\}}|j |f|qWd_WnDt k r8}z&|dk r(|j r(|j|WYdd}~Xn"X|dk rZ|j rZ|jddS)Ncs tdS)Nr)WriteSubprocessPipeProtor/)r)r/r0sz8BaseSubprocessTransport._connect_pipes..rcs tdS)Nr)ReadSubprocessPipeProtor/)r)r/r0rPsrcs tdS)Nr )rQr/)r)r/r0rPsr )rrr Zconnect_write_piperr Zconnect_read_piperrAssertionError call_soonrconnection_made Exception cancelledZ set_exception set_result) r)r,procr*_r6callbackdataexcr/)r)r0r(s8          z&BaseSubprocessTransport._connect_pipescGs2|jdk r|jj||fn|jj|f|dS)N)rr4rrS)r)cbr[r/r/r0_calls zBaseSubprocessTransport._callcCs|j|jj|||jdS)N)r^rZpipe_connection_lost _try_finish)r)rIr\r/r/r0_pipe_connection_lostsz-BaseSubprocessTransport._pipe_connection_lostcCs|j|jj||dS)N)r^rZpipe_data_received)r)rIr[r/r/r0_pipe_data_receivedsz+BaseSubprocessTransport._pipe_data_receivedcCs|dk st||jdks$t|j|jjrsz6BaseSubprocessTransport._try_finish..T)rrRrallrr>r^_call_connection_lost)r)r/r/r0r_s  z#BaseSubprocessTransport._try_finishc Cs*z|jj|Wdd|_d|_d|_XdS)N)rconnection_lostrr)r)r\r/r/r0rjs z-BaseSubprocessTransport._call_connection_lost)NN)r3 __module__ __qualname__rr9r r;r<r=r!rZPY34rFrGrHrJrKrLrNr?rr(r^r`rarcrdr_rj __classcell__r/r/)r.r0r s0) %  rc@s<eZdZddZddZddZddZd d Zd d Zd S)rOcCs||_||_d|_d|_dS)NF)rXrIr6re)r)rXrIr/r/r0rsz!WriteSubprocessPipeProto.__init__cCs ||_dS)N)r6)r)Z transportr/r/r0rTsz(WriteSubprocessPipeProto.connection_madecCsd|jj|j|jfS)Nz<%s fd=%s pipe=%r>)r.r3rIr6)r)r/r/r0r9sz!WriteSubprocessPipeProto.__repr__cCs d|_|jj|j|d|_dS)NT)rerXr`rI)r)r\r/r/r0rksz(WriteSubprocessPipeProto.connection_lostcCs|jjjdS)N)rXr pause_writing)r)r/r/r0rosz&WriteSubprocessPipeProto.pause_writingcCs|jjjdS)N)rXrresume_writing)r)r/r/r0rpsz'WriteSubprocessPipeProto.resume_writingN) r3rlrmrrTr9rkrorpr/r/r/r0rOs rOc@seZdZddZdS)rQcCs|jj|j|dS)N)rXrarI)r)r[r/r/r0 data_received$sz%ReadSubprocessPipeProto.data_receivedN)r3rlrmrqr/r/r/r0rQ!srQ)rrrCrrrZ coroutinesrlogrZSubprocessTransportrZ BaseProtocolrOZProtocolrQr/r/r/r0s     {