B -_N@sLdZddlZejdkZddlZddlZddlZddlZddlZddl Z ddl Z ddlm Z Gddde ZGdddeZGd d d eZerddlZddlZddlZGd d d ZnDddlZddlZddlZddlZeed dZeedrejZnejZddddddddddddd dgZerddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0e1ddddd d!d"d#d d$d%d&d'd(d)d*d+d,d-gGd.d/d/e2Z3gZ4d0d1Z5d2Z6d3Z7d4Z8d5d6Z9d7d8Z:dd9d:dZ;d;dZZ?dd>dd>d?d@dZ@dAdBZAdCdZBdDdZCGdEdde>ZDdS)FaSubprocesses with accessible I/O streams This module allows you to spawn processes, connect to their input/output/error pipes, and obtain their return codes. For a complete description of this module see the Python documentation. Main API ======== run(...): Runs a command, waits for it to complete, then returns a CompletedProcess instance. Popen(...): A class for flexibly executing a command in a new process Constants --------- DEVNULL: Special value that indicates that os.devnull should be used PIPE: Special value that indicates a pipe should be created STDOUT: Special value that indicates that stderr should go to stdout Older API ========= call(...): Runs a command, waits for it to complete, then returns the return code. check_call(...): Same as call() but raises CalledProcessError() if return code is not 0 check_output(...): Same as check_call() but returns the contents of stdout instead of a return code getoutput(...): Runs a command in the shell, waits for it to complete, then returns the output getstatusoutput(...): Runs a command in the shell, waits for it to complete, then returns a (exitcode, output) tuple NZwin32) monotonicc@s eZdZdS)SubprocessErrorN)__name__ __module__ __qualname__rr /usr/lib/python3.7/subprocess.pyr9src@s<eZdZdZd ddZddZeddZejd dZdS) CalledProcessErrorzRaised when run() is called with check=True and the process returns a non-zero exit status. Attributes: cmd, returncode, stdout, stderr, output NcCs||_||_||_||_dS)N) returncodecmdoutputstderr)selfr r r r rrr__init__CszCalledProcessError.__init__cCsb|jrN|jdkrNyd|jt|j fStk rJd|j|j fSXnd|j|jfSdS)NrzCommand '%s' died with %r.z)Command '%s' died with unknown signal %d.z.Command '%s' returned non-zero exit status %d.)r r signalZSignals ValueError)rrrr__str__IszCalledProcessError.__str__cCs|jS)z+Alias for output attribute, to match stderr)r )rrrrstdoutUszCalledProcessError.stdoutcCs ||_dS)N)r )rvaluerrrrZs)NN) rrr__doc__rrpropertyrsetterrrrrr <s   r c@s<eZdZdZd ddZddZeddZejd dZdS) TimeoutExpiredzThis exception is raised when the timeout expires while waiting for a child process. Attributes: cmd, output, stdout, stderr, timeout NcCs||_||_||_||_dS)N)r timeoutr r )rr rr r rrrrhszTimeoutExpired.__init__cCsd|j|jfS)Nz'Command '%s' timed out after %s seconds)r r)rrrrrnszTimeoutExpired.__str__cCs|jS)N)r )rrrrrrszTimeoutExpired.stdoutcCs ||_dS)N)r )rrrrrrvs)NN) rrrrrrrrrrrrrras   rc@s,eZdZdddddddddZddZdS) STARTUPINFOrN)dwFlags hStdInput hStdOutput hStdError wShowWindowlpAttributeListcCs0||_||_||_||_||_|p(dgi|_dS)N handle_list)rrrrrr )rrrrrrr rrrrs zSTARTUPINFO.__init__cCs@|j}d|kr"t|d|d<t|j|j|j|j|j|dS)Nr!)rrrrrr ) r copylistrrrrrr)rZ attr_listrrr_copys zSTARTUPINFO._copy)rrrrr$rrrrrsrZPIPE_BUFi PollSelectorPopenPIPESTDOUTcall check_callgetstatusoutput getoutput check_outputrunDEVNULLCompletedProcess)CREATE_NEW_CONSOLECREATE_NEW_PROCESS_GROUPSTD_INPUT_HANDLESTD_OUTPUT_HANDLESTD_ERROR_HANDLESW_HIDESTARTF_USESTDHANDLESSTARTF_USESHOWWINDOWABOVE_NORMAL_PRIORITY_CLASSBELOW_NORMAL_PRIORITY_CLASSHIGH_PRIORITY_CLASSIDLE_PRIORITY_CLASSNORMAL_PRIORITY_CLASSREALTIME_PRIORITY_CLASSCREATE_NO_WINDOWDETACHED_PROCESSCREATE_DEFAULT_ERROR_MODECREATE_BREAKAWAY_FROM_JOBr1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBc@s6eZdZdZejfddZddZddZeZ eZ dS) HandleFcCs|jsd|_||dS)NT)closed)r CloseHandlerrrClosesz Handle.ClosecCs |jsd|_t|StddS)NTzalready closed)rDintr)rrrrDetachsz Handle.DetachcCsd|jjt|fS)Nz%s(%d)) __class__rrG)rrrr__repr__szHandle.__repr__N) rrrrD_winapirErFrHrJ__del__rrrrrrCs rCc CsTxNtddD]>}|jtjd}|dk ryt|Wqtk rJYqXqWdS)N) _deadstate)_active_internal_pollsysmaxsizeremover)ZinstZresrrr_cleanupsrScCs*g}tjj}|dkr&|dd||S)zgReturn a list of command-line arguments reproducing the current optimization settings in sys.flags.r-O)rPflagsoptimizeappend)argsrrrr"_optim_args_from_interpreter_flagss r]c Csbddddddd}t}x:|D].\}}ttj|}|dkr"|d ||q"Wtjjrh|d n$tjjrz|d tjjr|d tj d d }tjj }ttdi}d|k}|dkr| dn|r| d|r| dx|D]}|d|qW|r| dxJdD]B}||kr||} | dkr>|} n d|| f} | d| fqW|S)z}Return a list of command-line arguments reproducing the current settings in sys.flags, sys.warnoptions and sys._xoptions.dBSvbq)debugdont_write_bytecodeno_siteverbose bytes_warningquietrrWz-Iz-Ez-sN _xoptionsdevzerror::BytesWarningzdefault::BytesWarningdefaultz-W)z-Xrk)Z faulthandler tracemallocZ importtimeZshowalloccountZ showrefcountutf8Tz%s=%sz-X) r]itemsgetattrrPrYr[isolatedignore_environment no_user_site warnoptionsrhrRextend) Z flag_opt_mapr\flagZoptraZwarnoptsrhZxoptionsdev_moderargrrr_args_from_interpreter_flagssN              rz)rc Os>t||*}y |j|dS|YnXWdQRXdS)zRun command with arguments. Wait for command to complete or timeout, then return the returncode attribute. The arguments are the same as for the Popen constructor. Example: retcode = call(["ls", "-l"]) )rN)r&waitkill)r popenargskwargsprrrr);s   cOs6t||}|r2|d}|dkr(|d}t||dS)aORun command with arguments. Wait for command to complete. If the exit code was zero then return, otherwise raise CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute. The arguments are the same as for the call function. Example: check_call(["ls", "-l"]) r\Nr)r)getr )r}r~retcoder rrrr*Ls   cOsTd|krtdd|kr<|ddkr<|ddr4dnd|d<t|t|d d |jS) aRun command with arguments and return its output. If the exit code was non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute and output in the output attribute. The arguments are the same as for the Popen constructor. Example: >>> check_output(["ls", "-l", "/dev/null"]) b'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n' The stdout argument is not allowed as it is used internally. To capture standard error in the result, use stderr=STDOUT. >>> check_output(["/bin/sh", "-c", ... "ls -l non_existent_file ; exit 0"], ... stderr=STDOUT) b'ls: non_existent_file: No such file or directory\n' There is an additional optional argument, "input", allowing you to pass a string to the subprocess's stdin. If you use this argument you may not also use the Popen constructor's "stdin" argument, as it too will be used internally. Example: >>> check_output(["sed", "-e", "s/foo/bar/"], ... input=b"when in the course of fooman events\n") b'when in the course of barman events\n' By default, all communication is in bytes, and therefore any "input" should be bytes, and the return value wil be bytes. If in text mode, any "input" should be a string, and the return value will be a string decoded according to locale encoding, or by "encoding" if set. Text mode is triggered by setting any of text, encoding, errors or universal_newlines. rz3stdout argument not allowed, it will be overridden.inputNuniversal_newlinesFT)rrcheck)rrr.r'r)rr}r~rrrr-_s #c@s*eZdZdZd ddZddZddZdS) r0aEA process that has finished running. This is returned by run(). Attributes: args: The list or str args passed to run(). returncode: The exit code of the process, negative for signals. stdout: The standard output (None if not captured). stderr: The standard error (None if not captured). NcCs||_||_||_||_dS)N)r\r rr )rr\r rr rrrrszCompletedProcess.__init__cCshd|jd|jg}|jdk r4|d|j|jdk rP|d|jdt|jd|S)Nz args={!r}zreturncode={!r}z stdout={!r}z stderr={!r}z{}({})z, ) formatr\r rr[r typerjoin)rr\rrrrJs   zCompletedProcess.__repr__cCs |jrt|j|j|j|jdS)z6Raise CalledProcessError if the exit code is non-zero.N)r r r\rr )rrrrcheck_returncodesz!CompletedProcess.check_returncode)NN)rrrrrrJrrrrrr0s   F)rcapture_outputrrc Os|dk r d|krtdt|d<|rLd|ks4d|kr>> import subprocess >>> subprocess.getstatusoutput('ls /bin/ls') (0, '/bin/ls') >>> subprocess.getstatusoutput('cat /bin/junk') (1, 'cat: /bin/junk: No such file or directory') >>> subprocess.getstatusoutput('/bin/junk') (127, 'sh: /bin/junk: not found') >>> subprocess.getstatusoutput('/bin/kill $$') (-15, '') T)shelltextr rNrT )r-r(r r r )r dataZexitcodeZexrrrr+4s cCs t|dS)a%Return output (stdout or stderr) of executing cmd in a shell. Like getstatusoutput(), except the exit status is ignored and the return value is a string containing the command's output. Example: >>> import subprocess >>> subprocess.getoutput('ls /bin/ls') '/bin/ls' rl)r+)r rrrr,Ss c@seZdZdZdZdGddddd d Zed d Zejd d ZddZ ddZ ddZ e j ejfddZddZddZdHddZddZddZd d!ZdId"d#Zerd$d%Zd&d'Zd(d)Zd*d+Zdejejej fd,d-Z!d.d/Z"d0d1Z#d2d3Z$d4d5Z%d6d7Z&e&Z'nd8d%Zd9d+Ze(j)e(j*e(j+e(j,e(j-e(j.fd:d;Z/de(j0e(j1e2j3fdZ4d?d/Z"d@d3Z$dAdBZ5dCd5Z%dDd7Z&dEdFZ'dS)Jr&a Execute a child program in a new process. For a complete description of the arguments see the Python documentation. Arguments: args: A string, or a sequence of program arguments. bufsize: supplied as the buffering argument to the open() function when creating the stdin/stdout/stderr pipe file objects executable: A replacement program to execute. stdin, stdout and stderr: These specify the executed programs' standard input, standard output and standard error file handles, respectively. preexec_fn: (POSIX only) An object to be called in the child process just before the child is executed. close_fds: Controls closing or inheriting of file descriptors. shell: If true, the command will be executed through the shell. cwd: Sets the current directory before the child is executed. env: Defines the environment variables for the new process. text: If true, decode stdin, stdout and stderr using the given encoding (if set) or the system default otherwise. universal_newlines: Alias of text, provided for backwards compatibility. startupinfo and creationflags (Windows only) restore_signals (POSIX only) start_new_session (POSIX only) pass_fds (POSIX only) encoding and errors: Text mode encoding and error handling to use for file objects stdin, stdout and stderr. Attributes: stdin, stdout, stderr, pid, returncode FrTNTrr)encodingerrorsrcCsZtt|_d|_d|_|dkr(d}t|ts:tdt rP|dk rt dn8|rh|sht dt d}| dk rxt d|d krt d ||_d|_d|_d|_d|_d|_||_||_|dk r| dk rt| t|krtd ||||\}}}}}}t rN|dkrt|d }|dkr4t|d }|dkrNt|d }|pb|pb|pb| |_d |_d|_y|dkrt |d ||_|jrtj!|jd|dk||d|_|dkrt |d||_|jrtj!|j||d|_|dkrt |d||_|jrtj!|j||d|_|"|||||| | | || ||||||||WnxDt#d|j|j|jfD]*}y |$Wnt%k rYnXqnW|jsNg}|t&kr|'||t&kr|'||t&kr|'|t(|dr|'|j)xP|D]H}y*t r$t|t*r$|+n t,$|Wnt%k rFYnXqWYnXdS)zCreate new Popen instance.NFrTzbufsize must be an integerz0preexec_fn is not supported on Windows platformszpass_fds overriding close_fds.Tz2startupinfo is only supported on Windows platformsrz4creationflags is only supported on Windows platformszlCannot disambiguate when both text and universal_newlines are supplied but different. Pass one or the other.g?wbrl) write_throughline_bufferingrrrb)rr_devnull)-rS threadingZLock _waitpid_lock_input_communication_started isinstancerG TypeError _mswindowsrwarningswarnRuntimeWarningr\rrr pidr rrboolr _get_handlesmsvcrtZopen_osfhandlerH text_mode_sigint_wait_secs_closed_child_pipe_fdsioopen TextIOWrapper_execute_childfiltercloseOSErrorr'r[hasattrrrCrFos)rr\bufsize executablerrr preexec_fn close_fdsrcwdenvr startupinfo creationflagsrestore_signalsstart_new_sessionpass_fdsrrrp2creadp2cwritec2preadc2pwriteerrreaderrwritefZto_closefdrrrrs                            zPopen.__init__cCs|jS)N)r)rrrrr%szPopen.universal_newlinescCst||_dS)N)rr)rrrrrr+scCs |||}|ddddS)Nz r )decodereplace)rrrrrrr_translate_newlines/s zPopen._translate_newlinescCs|S)Nr)rrrr __enter__3szPopen.__enter__cCs|jr|j|jr |jz|jr2|jWd|tkrz|jdkrpy|j|jdWntk rnYnXd|_dS|XdS)Nr)r) rrr rKeyboardInterruptr_waitrr{)rexc_typer tracebackrrr__exit__6s    zPopen.__exit__cCsT|js dS|jdkr(|d|jt|d|j|d|jdkrPtdk rPt|dS)Nzsubprocess %s is still running)source)rM)_child_createdr rResourceWarningrOrNr[)rZ_maxsizeZ_warnrrrrLRs    z Popen.__del__cCs"t|dsttjtj|_|jS)Nr)rrrdevnullO_RDWRr)rrrr _get_devnullas zPopen._get_devnullc Cs|rZy|j|WnDtk r(Yn2tk rX}z|jtjkrFnWdd}~XYnXy|jWnDtk r|Yn2tk r}z|jtjkrnWdd}~XYnXdS)N)rwriteBrokenPipeErrorrerrnoZEINVALr)rrexcrrr _stdin_writefs"  zPopen._stdin_writec CsT|jr|rtd|dkr|js|j|j|jgddkrd}d}|jrT||n6|jrp|j}|jn|jr|j}|j| n|dk rt |}nd}zy| |||\}}Wnht k r,|dk rt |j||}n|j}d|_y|j|dWntk r$YnXYnXWdd|_X|j ||d}||fS)a9Interact with process: Send data to stdin and close it. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional "input" argument should be data to be sent to the child process, or None, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr). By default, all communication is in bytes, and therefore any "input" should be bytes, and the (stdout, stderr) will be bytes. If in text mode (indicated by self.text_mode), any "input" should be a string, and (stdout, stderr) will be strings decoded according to locale encoding, or by "encoding" if set. Text mode is triggered by setting any of text, encoding, errors or universal_newlines. z.Cannot send input after starting communicationNrr)rT)rrrrr countrreadrr{_time _communicaterminr_remaining_timerr)rrrrr endtimesigint_timeoutstsrrrrsD         zPopen.communicatecCs|S)zSCheck if child process has terminated. Set and return returncode attribute.)rO)rrrrrsz Popen.pollcCs|dkr dS|tSdS)z5Convenience for _communicate when computing timeouts.N)r)rrrrrrszPopen._remaining_timecCs&|dkr dSt|kr"t|j|dS)z2Convenience for checking if a timeout has expired.N)rrr\)rr orig_timeoutrrr_check_timeouts zPopen._check_timeoutc Cs|dk rt|}y |j|dStk r|dk rJt|j||}n|j}d|_y|j|dWntk rzYnXYnXdS)z=Wait for child process to terminate; returns self.returncode.N)rr)rrrrrrr)rrrrrrrr{s  z Popen.waitc Cs~|dkr|dkr|dkrdSd\}}d\}}d\}} |dkrtttj}|dkrtdd\}} t|}t| nh|tkrtdd\}}t|t|}}n<|tkrt | }n$t |t rt |}nt | }||}|dkr*ttj}|dkrtdd\} }t|}t| nn|tkrXtdd\}}t|t|}}n@|tkrrt | }n&t |t rt |}nt | }||}|dkrttj} | dkrdtdd\} } t| } t| n~|tkrtdd\}} t|t| }} nP|tkr$|} n@|tkr>t | } n&t |t rVt |} nt | } || } |||||| fS)z|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite N)rTrTrTrTrTrT)rTrTr)rKZ GetStdHandler3Z CreatePiperCrEr'r/rZ get_osfhandlerrrGfileno_make_inheritabler4r5r() rrrr rrrrrr_rrrrsn                        zPopen._get_handlescCs&tt|tddtj}t|S)z2Return a duplicate of handle, which is inheritablerrl)rKZDuplicateHandleZGetCurrentProcessZDUPLICATE_SAME_ACCESSrC)rhandlehrrrr=s  zPopen._make_inheritablecCstdd|DS)zFilter out console handles that can't be used in lpAttributeList["handle_list"] and make sure the list isn't empty. This also removes duplicate handles.cSs,h|]$}|d@dks$t|tjkr|qS))rKZ GetFileTypeZFILE_TYPE_CHAR).0rrrr Ms z,Popen._filter_handle_list..)r#)rr!rrr_filter_handle_listFszPopen._filter_handle_listc Cs|r tdt|tst|}|dkr.t}n|}d| ||fk}|rj|jtjO_| |_ ||_ ||_ |j }t |od|ko|d}|s|r|r|dkri}|_ t|dg}|d<|r|t| t|t|g7}|||dd<|r|s tdtd}| rF|jtjO_tj|_tjdd}d ||}z@t||ddt| | ||dk rtt|nd| \}}}}Wd| dkr| |dkr||dkr|t|d rt|j d |_!Xd |_"t#||_$||_%t&|dS) z$Execute program (MS Windows version)z"pass_fds not supported on Windows.NrTr!z?startupinfo.lpAttributeList['handle_list'] overriding close_fdsFZCOMSPECzcmd.exez {} /c "{}"rT)'AssertionErrorrstrrrr$rrKr7rrrr rr#rrGrrrrr8r6rrenvironrZ CreateProcessfspathrFrrrrrrC_handlerrE)rr\rrrrrrrrrrrrrrrZunused_restore_signalsZunused_start_new_sessionZuse_std_handlesZattribute_listZhave_handle_listr!ZcomspecZhpZhtrtidrrrrSsl           zPopen._execute_childcCs,|jdkr&||jd|kr&||j|_|jS)zCheck if child process has terminated. Returns returncode attribute. This method is called by __del__, so it can only refer to objects in its local scope. Nr)r r)rrMZ_WaitForSingleObjectZ_WAIT_OBJECT_0Z_GetExitCodeProcessrrrrOs  zPopen._internal_pollcCs^|dkrtj}n t|d}|jdkrXt|j|}|tjkrJt|j|t |j|_|jS)z-Internal implementation of wait() on Windows.Ni) rKZINFINITErGr WaitForSingleObjectrZ WAIT_TIMEOUTrr\GetExitCodeProcess)rrZtimeout_millisrrrrrs    z Popen._waitcCs|||dS)N)r[rr)rZfhbufferrrr _readerthreadszPopen._readerthreadcCs\|jrBt|dsBg|_tj|j|j|jfd|_d|j_|j|j rt|dsg|_ tj|j|j |j fd|_ d|j _|j |j r| ||jdk r|j|||jrt|j||j dk r|j |||j rt|j|d}d}|jr|j}|j|j r0|j }|j |dk rB|d}|dk rT|d}||fS)N _stdout_buff)targetr\T _stderr_buffr)rrrrZThreadrZ stdout_threadZdaemonstartr rZ stderr_threadrrrrZis_aliverr\r)rrrrrr rrrrsF             zPopen._communicatecCsl|jdk rdS|tjkr"|nF|tjkr>t|jtjn*|tjkrZt|jtjnt d |dS)zSend a signal to the process.NzUnsupported signal: {}) r rSIGTERM terminateZ CTRL_C_EVENTrr|rZCTRL_BREAK_EVENTrr)rsigrrr send_signals     zPopen.send_signalcCsX|jdk rdSyt|jdWn2tk rRt|j}|tjkrH||_YnXdS)zTerminates the process.Nrl)r rKZTerminateProcessrPermissionErrorrZ STILL_ACTIVE)rZrcrrrr s   zPopen.terminatec Cs,d\}}d\}}d\}} |dkr"n@|tkr8t\}}n*|tkrJ|}nt|trZ|}n|}|dkrln@|tkrt\}}n*|tkr|}nt|tr|}n|}|dkrnf|tkrt\}} nP|tkr|dkr|} n t j } n.|tkr|} nt|tr|} n|} |||||| fS)z|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite )rTrTNrT) r'rpiper/rrrGrr(rP __stdout__) rrrr rrrrrrrrrr1sJ        c*st|ttfr|g}nt|}| rLttdr0dnd}|dg|}rL|d<dkr\|d}t\}}g}x |dkr||t |}qrWx|D]}t |qWzz|dk rg}xL| D]:\}}t |}d|krt d ||dt |qWnd}t tjr,f}ntfd d t|D}t|}||t|||tttt|||| | | |||||||||_d |_Wdt |Xt|d d}| dkr| dkr| |krt | |dkr| dkr||krt ||dkr.|dkr.||kr.t ||dk rBt |d |_t}x0t|d} || 7}| rxt|dkrPPqPWWdt |X|ry6t |jd\}!}"|!|jkr|!|"ntj"|_#Wnt$k rYnXy|%dd\}#}$}%|%&}%Wn,t k r.d}#d}$d't|}%YnXtt(|#&dt)}&t*|&t+r|$rt|$d}'|%dk}(|(rvd}%|})n|})|'dkrt,|'}%|'t-j.kr|%dt/|)7}%|&|'|%|)|&|%dS)zExecute program (POSIX version)Zgetandroidapilevelz/system/bin/shz/bin/shz-crNr=z!illegal environment variable namec3s"|]}tjt|VqdS)N)rpathrfsencode)rdir)rrr sz'Popen._execute_child..TrrTiP:rsSubprocessError0z#Bad exception data from child: {!r}asciiZnoexecrz: )0rrbytesr#rrPrr r[duprrprrrdirnametuple get_exec_pathsetadd_posixsubprocessZ fork_execsortedmaprGrrrqr bytearrayrrwaitpid_handle_exitstatusrQr ChildProcessErrorsplitrrbuiltinsr issubclassrstrerrorrZENOENTrepr)*rr\rrrrrrrrrrrrrrrrrZ unix_shellZorig_executableZ errpipe_readZ errpipe_writeZlow_fds_to_closeZlow_fdZenv_listkraZexecutable_listZ fds_to_keepZ devnull_fdZ errpipe_datapartrrZexception_nameZ hex_errnoZerr_msgZchild_exception_typeZ errno_numZchild_exec_never_calledZ err_filenamer)rrrgs                                 cCsL||r|| |_n2||r*|||_n||r@|| |_ntddS)z:All callers to this function MUST hold self._waitpid_lock.zUnknown child exit status!N)r r)rrZ _WIFSIGNALEDZ _WTERMSIGZ _WIFEXITEDZ _WEXITSTATUSZ _WIFSTOPPEDZ _WSTOPSIGrrrr$s zPopen._handle_exitstatusc Cs|jdkr|jdsdSzy8|jdk r.|jS||j|\}}||jkrR||WnBtk r}z$|dk rv||_n|j|krd|_Wdd}~XYnXWd|jX|jS)zCheck if child process has terminated. Returns returncode attribute. This method is called by __del__, so it cannot reference anything outside of the local scope (nor can any methods it calls). NFr)r racquirerr$rrrelease)rrMZ_waitpidZ_WNOHANGZ_ECHILDrrerrrrOs      cCs>yt|j|\}}Wntk r4|j}d}YnX||fS)z:All callers to this function MUST hold self._waitpid_lock.r)rr#rr%)rZ wait_flagsrrrrr _try_wait+s  zPopen._try_waitc Cs&|jdk r|jS|dk rt|}d}x|jdrzL|jdk rBP|tj\}}||jksh|dksht||jkr~| |PWd|j X| |}|dkrt |j |t|d|d}t|q(WnTxR|jdkr|j6|jdk rP|d\}}||jkr| |WdQRXqW|jS)z+Internal implementation of wait() on POSIX.NgMb@?Frrg?)r rrr-r0rWNOHANGrrr$r.rrr\rtimeZsleep)rrrZdelayrrZ remainingrrrr8s:           c Cs|jrX|jsXy|jWntk r.YnX|sXy|jWntk rVYnXd}d}|jsi|_|jr~g|j|j<|jrg|j|j<|jr|j|j}|jr|j|j}|||j rt |j }t }|jr|r| |jt j|jr | |jt j|jr"| |jt jxJ|rn||}|dk rZ|dkrZt|j|||} |||x| D]\} } | j|jkr||j|jt} y|jt| j| 7_Wn,tk r|| j| jYn*X|jt|j krd|| j| jnP| j|j|jfkrvt| jd} | sR|| j| j|j| j| qvWq&WWdQRX|j ||d|dk rd!|}|dk rd!|}|j"r|dk r|#||jj$|jj%}|dk r|#||jj$|jj%}||fS)Nri)rr)&rrflushrrZ_fileobj2outputrr _save_inputr memoryview_PopenSelectorregister selectorsZ EVENT_WRITEZ EVENT_READZget_maprrr\selectrZfileobj _input_offset _PIPE_BUFrrrZ unregisterrrr[r{rrrrr)rrrrrr Z input_viewZselectorrZreadykeyZeventschunkrrrrras                  (        cCsF|jrB|jdkrBd|_||_|dk rB|jrB|j|jj|jj|_dS)Nr)rrr:rencoderr)rrrrrr4s  zPopen._save_inputcCs|jdkrt|j|dS)zSend a signal to the process.N)r rr|r)rr rrrr s cCs|tjdS)z/Terminate the process with SIGTERM N)r rr)rrrrr scCs|tjdS)z*Kill the process with SIGKILL N)r rSIGKILL)rrrrr|sz Popen.kill)rTNNNNNTFNNNNrTFr)NN)N)6rrrrrrrrrrrrrPrQrrrLrrrrrrr{rrrrrrKrZ WAIT_OBJECT_0rrOrrrr r r|r WIFSIGNALEDWTERMSIG WIFEXITED WEXITSTATUS WIFSTOPPEDWSTOPSIGr$r#r1rZECHILDr0r4rrrrr&`sl-  D H  a46" )a )ErrPplatformrrrr2rr'rrrr Exceptionrr rrrrKrrr9r8rqr;rr%r6ZSelectSelector__all__r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrvrGrCrNrSr'r(r/r]rzr)r*r-objectr0r.rr+r,r&rrrr*st  %     P    ;/";I