e f%@s4dZddlZejdkZddlZddlZddlZddlZddlZddl Z ddl Z yddlm Z Wn"e k rddlmZ YnXGdddeZGdd d eZGd d d eZer0ddlZddlZddlZGd d d ZnddlZddlZddlZyddlZWne k rddlZYnXeeddZeedrejZn ejZddddddddd dg Z er]ddlm!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(e j)dddddd d!d"gGd#d$d$e*Z+nyej,d%Z-Wnd&Z-YnXgZ.d'd(Z/d9Z0d:Z1d;Z2d,d-Z3d.d/Z4d0dd1dZ5d2dZ6d0dd3dZ7d4d5Z8d6dZ9d7dZ:e;Z<Gd8dde;Z=dS)>> retcode = subprocess.call(["ls", "-l"]) check_call(*popenargs, **kwargs): Run 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 Popen constructor. Example: >>> subprocess.check_call(["ls", "-l"]) 0 getstatusoutput(cmd): Return (status, output) of executing cmd in a shell. Execute the string 'cmd' in a shell with 'check_output' and return a 2-tuple (status, output). Universal newlines mode is used, meaning that the result with be decoded to a string. A trailing newline is stripped from the output. The exit status for the command can be interpreted according to the rules for the function 'wait'. Example: >>> subprocess.getstatusoutput('ls /bin/ls') (0, '/bin/ls') >>> subprocess.getstatusoutput('cat /bin/junk') (256, 'cat: /bin/junk: No such file or directory') >>> subprocess.getstatusoutput('/bin/junk') (256, 'sh: /bin/junk: not found') getoutput(cmd): 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: >>> subprocess.getoutput('ls /bin/ls') '/bin/ls' check_output(*popenargs, **kwargs): Run 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: >>> output = subprocess.check_output(["ls", "-l", "/dev/null"]) 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. Exceptions ---------- Exceptions raised in the child process, before the new program has started to execute, will be re-raised in the parent. Additionally, the exception object will have one extra attribute called 'child_traceback', which is a string containing traceback information from the child's point of view. The most common exception raised is OSError. This occurs, for example, when trying to execute a non-existent file. Applications should prepare for OSErrors. A ValueError will be raised if Popen is called with invalid arguments. Exceptions defined within this module inherit from SubprocessError. check_call() and check_output() will raise CalledProcessError if the called process returns a non-zero return code. TimeoutExpired be raised if a timeout was specified and expired. Security -------- Unlike some other popen functions, this implementation will never call /bin/sh implicitly. This means that all characters, including shell metacharacters, can safely be passed to child processes. Popen objects ============= Instances of the Popen class have the following methods: poll() Check if child process has terminated. Returns returncode attribute. wait() Wait for child process to terminate. Returns returncode attribute. communicate(input=None) Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional input argument should be a string to be sent to the child process, or None, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr). Note: The data read is buffered in memory, so do not use this method if the data size is large or unlimited. The following attributes are also available: stdin If the stdin argument is PIPE, this attribute is a file object that provides input to the child process. Otherwise, it is None. stdout If the stdout argument is PIPE, this attribute is a file object that provides output from the child process. Otherwise, it is None. stderr If the stderr argument is PIPE, this attribute is file object that provides error output from the child process. Otherwise, it is None. pid The process ID of the child process. returncode The child return code. A None value indicates that the process hasn't terminated yet. A negative value -N indicates that the child was terminated by signal N (POSIX only). Replacing older functions with the subprocess module ==================================================== In this section, "a ==> b" means that b can be used as a replacement for a. Note: All functions in this section fail (more or less) silently if the executed program cannot be found; this module raises an OSError exception. In the following examples, we assume that the subprocess module is imported with "from subprocess import *". Replacing /bin/sh shell backquote --------------------------------- output=`mycmd myarg` ==> output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0] Replacing shell pipe line ------------------------- output=`dmesg | grep hda` ==> p1 = Popen(["dmesg"], stdout=PIPE) p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE) output = p2.communicate()[0] Replacing os.system() --------------------- sts = os.system("mycmd" + " myarg") ==> p = Popen("mycmd" + " myarg", shell=True) pid, sts = os.waitpid(p.pid, 0) Note: * Calling the program through the shell is usually not required. * It's easier to look at the returncode attribute than the exitstatus. A more real-world example would look like this: try: retcode = call("mycmd" + " myarg", shell=True) if retcode < 0: print("Child was terminated by signal", -retcode, file=sys.stderr) else: print("Child returned", retcode, file=sys.stderr) except OSError as e: print("Execution failed:", e, file=sys.stderr) Replacing os.spawn* ------------------- P_NOWAIT example: pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg") ==> pid = Popen(["/bin/mycmd", "myarg"]).pid P_WAIT example: retcode = os.spawnlp(os.P_WAIT, "/bin/mycmd", "mycmd", "myarg") ==> retcode = call(["/bin/mycmd", "myarg"]) Vector example: os.spawnvp(os.P_NOWAIT, path, args) ==> Popen([path] + args[1:]) Environment example: os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env) ==> Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"}) Nwin32) monotonic)timec@seZdZdS)SubprocessErrorN)__name__ __module__ __qualname__r r //opt/alt/python34/lib64/python3.4/subprocess.pyrks rc@s1eZdZdZdddZddZdS)CalledProcessErrorzThis exception is raised when a process run by check_call() or check_output() returns a non-zero exit status. The exit status will be stored in the returncode attribute; check_output() will also store the output in the output attribute. NcCs||_||_||_dS)N) returncodecmdoutput)selfr r rr r r __init__ts  zCalledProcessError.__init__cCsd|j|jfS)Nz-Command '%s' returned non-zero exit status %d)r r )rr r r __str__xszCalledProcessError.__str__)rrr__doc__rrr r r r r ns r c@s1eZdZdZdddZddZdS)TimeoutExpiredz]This exception is raised when the timeout expires while waiting for a child process. NcCs||_||_||_dS)N)r timeoutr)rr rrr r r rs  zTimeoutExpired.__init__cCsd|j|jfS)Nz'Command '%s' timed out after %s seconds)r r)rr r r rszTimeoutExpired.__str__)rrrrrrr r r r r|s rc@s.eZdZdZdZdZdZdZdS) STARTUPINFOrN)rrrdwFlags hStdInput hStdOutput hStdError wShowWindowr r r r rs rZPIPE_BUFi PollSelectorPopenPIPESTDOUTcall check_callgetstatusoutput getoutput check_outputDEVNULL)CREATE_NEW_CONSOLECREATE_NEW_PROCESS_GROUPSTD_INPUT_HANDLESTD_OUTPUT_HANDLESTD_ERROR_HANDLESW_HIDESTARTF_USESTDHANDLESSTARTF_USESHOWWINDOWr%r&r'r(r)r*r+r,c@sLeZdZdZejddZddZddZeZ eZ dS) HandleFcCs#|jsd|_||ndS)NT)closed)r CloseHandler r r Closes  z Handle.ClosecCs,|jsd|_t|StddS)NTzalready closed)r.int ValueError)rr r r Detachs   z Handle.DetachcCsdt|S)Nz Handle(%d))r1)rr r r __repr__szHandle.__repr__N) rrrr._winapir/r0r3r4__del__rr r r r r-s   r- SC_OPEN_MAXc CsixbtddD]P}|jdtj}|dk rytj|Wqatk r]YqaXqqWdS)N _deadstate)_active_internal_pollsysmaxsizeremover2)Zinstresr r r _cleanups  r@c Gs1x*y||SWqtk r(wYqXqWdS)N)InterruptedError)funcargsr r r _eintr_retry_calls  rGcCsi dd6dd6dd6dd6d d 6d d 6d d6dd6dd6}g}xP|jD]B\}}ttj|}|dkrX|jd||qXqXWx"tjD]}|jd|qW|S)znReturn a list of command-line arguments reproducing the current settings in sys.flags and sys.warnoptions.ddebugOoptimizeBdont_write_bytecodes no_user_siteSno_siteEignore_environmentvverboseb bytes_warningqquietr-z-W)itemsgetattrr<flagsappend warnoptions)Z flag_opt_maprFZflagZoptrTr r r _args_from_interpreter_flagss$  r`rcOsRt||=}y|jd|SWn|j|jYnXWdQXdS)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)rwaitkill)r popenargskwargspr r r rs  cOsSt||}|rO|jd}|dkr=|d}nt||ndS)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"]) rFNr)rgetr )rcrdretcoder r r r r s   cOs;d|krtdnd|kr`d|krBtdn|d}|d=t|d>> 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' If universal_newlines=True is passed, the return value will be a string rather than bytes. stdoutz3stdout argument not allowed, it will be overridden.inputstdinz/stdin and input arguments may not both be used.Nrr) r2rr communicaterrbrFrapollr )rrcrdZ inputdataZprocessrZ unused_errrgr r r r#2s0          !cCsGg}d}x+|D]#}g}|r5|jdnd|kpQd|kpQ| }|rj|jdnx|D]}|dkr|j|qq|dkr|jdt|dg}|jdqq|r|j|g}n|j|qqW|r|j|n|r|j||jdqqWdj|S) a Translate a sequence of arguments into a command line string, using the same rules as the MS C runtime: 1) Arguments are delimited by white space, which is either a space or a tab. 2) A string surrounded by double quotation marks is interpreted as a single argument, regardless of white space contained within. A quoted string can be embedded in an argument. 3) A double quotation mark preceded by a backslash is interpreted as a literal double quotation mark. 4) Backslashes are interpreted literally, unless they immediately precede a double quotation mark. 5) If backslashes immediately precede a double quotation mark, every pair of backslashes is interpreted as a literal backslash. If the number of backslashes is odd, the last backslash escapes the next double quotation mark as described in rule 3. F  "\rBz\")r^lenextendjoin)seqresultZ needquoteargZbs_bufcr r r list2cmdlinems4       rycCsy(t|dddddt}d}Wn7tk ra}z|j}|j}WYdd}~XnX|d ddkr|dd }n||fS) a Return (status, output) of executing cmd in a shell. Execute the string 'cmd' in a shell with 'check_output' and return a 2-tuple (status, output). Universal newlines mode is used, meaning that the result with be decoded to a string. A trailing newline is stripped from the output. The exit status for the command can be interpreted according to the rules for the function 'wait'. Example: >>> import subprocess >>> subprocess.getstatusoutput('ls /bin/ls') (0, '/bin/ls') >>> subprocess.getstatusoutput('cat /bin/junk') (256, 'cat: /bin/junk: No such file or directory') >>> subprocess.getstatusoutput('/bin/junk') (256, 'sh: /bin/junk: not found') shellTuniversal_newlinesstderrrNrA r~)r#rr rr )r dataZstatusZexr r r r!s  cCst|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' rA)r!)r r r r r"s c@s#eZdZdZd=dddddeddddddddfddZdd Zd d Zd d Ze j ddZ ddZ ddddZ ddZddZddZer\ddZddZddZdejejejd d!Zddd"d#Zd$d%Zd&d'Zd(d)Zd*d+ZeZnd,dZd-d.Z d/dZe!j"e!j#e!j$e!j%d0d1Z&de!j'e!j(e)j*d2d!Zd3d4Z+ddd5d#Zd6d'Zd7d8Z,d9d)Zd:d+Zd;d<ZdS)>rFrANrTcCsttj|_d|_d|_|dkr=d}nt|ts[tdnt r|dk r|t dn|dk p|dk p|dk }|t kr|rd}qd}qS|rS|rSt dqSnq|t krd}n|r| rt j dtd}n| dk r8t d n|d krSt d n||_d|_d|_d|_d|_d|_| |_|j|||\}}}}}}t r7|dkrtj|jd }n|dkr tj|jd }n|dkr7tj|jd }q7n|dkrtj|d ||_| rtj|jd dd|dk|_qn|dkrtj|d||_| rtj|j|_qn|dkrtj|d||_| rtj|j|_qnd|_yD|j|||||| | | || ||||||||WnxLtd|j|j|jfD])}y|j Wqt!k rYqXqW|jsyg}|t"kr|j#|n|t"kr|j#|n|t"kr|j#|nt$|dr?|j#|j%nx7|D],}yt&j |WqFt!k rqYqFXqFWnYnXdS)zCreate new Popen instance.NFrAzbufsize must be an integerz0preexec_fn is not supported on Windows platformsTzSclose_fds is not supported on Windows platforms if you redirect stdin/stdout/stderrzpass_fds overriding close_fds.z2startupinfo is only supported on Windows platformsrz4creationflags is only supported on Windows platformswbZ write_throughline_bufferingrb_devnullr~r~r~r~r~r~r~)'r@ threadingZLock _waitpid_lock_input_communication_started isinstancer1 TypeError mswindowsr2_PLATFORM_DEFAULT_CLOSE_FDSwarningswarnRuntimeWarningrFrjrhr|pidr r{ _get_handlesmsvcrtZopen_osfhandler3ioopen TextIOWrapper_closed_child_pipe_fds_execute_childfiltercloseOSErrorrr^hasattrros)rrFbufsize executablerjrhr| preexec_fn close_fdsrzcwdenvr{ startupinfo creationflagsrestore_signalsstart_new_sessionpass_fdsZ any_stdio_setp2creadp2cwritec2preadc2pwriteerrreaderrwritefZto_closefdr r r rs                       '         (         zPopen.__init__cCs+|j|}|jddjddS)Nz r} )decodereplace)rrencodingr r r _translate_newlinestszPopen._translate_newlinescCs|S)Nr )rr r r __enter__xszPopen.__enter__c Csa|jr|jjn|jr2|jjnz|jrN|jjnWd|jXdS)N)rhrr|rjra)rtypevalue tracebackr r r __exit__{s   zPopen.__exit__cCsL|js dS|jd||jdkrHtdk rHtj|ndS)Nr9)_child_createdr;r r:r^)rZ_maxsizer r r r6s  z Popen.__del__cCs4t|ds-tjtjtj|_n|jS)Nr)rrrdevnullO_RDWRr)rr r r _get_devnullszPopen._get_devnullcCs|jr|rtdn|dkrR|j rR|j|j|jgjddkrRd}d}|jr|ry|jj|Wqtk r}z/|jtj kr|jtj krnWYdd}~XqXn|jj nV|jrt |jj }|jj n+|jrEt |jj }|jj n|jni|dk rnt|}nd}z|j|||\}}Wdd|_X|jd|j|}||fS)acInteract with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional input argument should be bytes to be sent to the child process, or None, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr).z.Cannot send input after starting communicationNrBTr)rr2rjrhr|countwritererrnoEPIPEEINVALrrGreadra_time _communicate_remaining_time)rrirrhr|eendtimestsr r r rks: ' $     zPopen.communicatecCs |jS)N)r;)rr r r rlsz Popen.pollcCs|dkrdS|tSdS)z5Convenience for _communicate when computing timeouts.N)r)rrr r r rs zPopen._remaining_timecCs8|dkrdSt|kr4t|j|ndS)z2Convenience for checking if a timeout has expired.N)rrrF)rr orig_timeoutr r r _check_timeouts zPopen._check_timeoutc Cs|dkr(|dkr(|dkr(d Sd \}}d\}}d\}} |dkrtjtj}|dkrGtjdd\}} t|}tj| qGn|tkrtjdd\}}t|t|}}nZ|tkrtj |j }n6t |t r2tj |}ntj |j }|j|}|dkrtjtj}|dkrQtjdd\} }t|}tj| qQn|tkrtjdd\}}t|t|}}nZ|tkrtj |j }n6t |t r<tj |}ntj |j }|j|}|dkrtjtj} | dkrptjdd\} } t| } tj| qpn|tkrtjdd\}} t|t| }} no|tkr|} nZ|tkr:tj |j } n6t |t r[tj |} ntj |j } |j| } |||||| fS)z|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite NrArr~r~r~r~r~r~)r~r~r~r~r~r~r~r~)r~r~r~r~)r~r~r~r~)r~r~)r5Z GetStdHandler'Z CreatePiper-r/rr$rZ get_osfhandlerrr1fileno_make_inheritabler(r)r) rrjrhr|rrrrrr_r r r rsn$                    zPopen._get_handlescCs7tjtj|tjddtj}t|S)z2Return a duplicate of handle, which is inheritablerrA)r5ZDuplicateHandleZGetCurrentProcessZDUPLICATE_SAME_ACCESSr-)rZhandlehr r r r(s   zPopen._make_inheritablecCst|tst|}n|dkr6t}nd| ||fkr{|jtjO_| |_||_||_ n| r|jtj O_tj |_ t jjdd}dj||}nz>tj||ddt| | ||| \}}}}Wd| d kr#| jn|d kr<|jn|d krU|jnt|drwt j|jnXd|_t||_||_tj|dS) z$Execute program (MS Windows version)NrAZCOMSPECzcmd.exez {} /c "{}"rTr~r~r~r~)rstrryrrr5r+rrrr,r*rrenvironrfformatZ CreateProcessr1r0rrrrr-_handlerr/)rrFrrrrrrrrrzrrrrrrZunused_restore_signalsZunused_start_new_sessionZcomspecZhpZhtrtidr r r r1sD                 zPopen._execute_childcCsF|jdkr?||jd|kr?||j|_q?n|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)rr9Z_WaitForSingleObjectZ_WAIT_OBJECT_0Z_GetExitCodeProcessr r r r;ns zPopen._internal_pollcCs|dk r|j|}n|dkr6tj}nt|d}|jdkrtj|j|}|tjkrt|j |ntj |j|_n|jS)zOWait for child process to terminate. Returns returncode attribute.Ni) rr5ZINFINITEr1r WaitForSingleObjectrZ WAIT_TIMEOUTrrFGetExitCodeProcess)rrrZtimeout_millisrvr r r ras     z Popen.waitcCs!|j|j|jdS)N)r^rr)rZfhbufferr r r _readerthreadszPopen._readerthreadcCs|jrht|d rhg|_tjd|jd|j|jf|_d|j_|jjn|j rt|d rg|_ tjd|jd|j |j f|_ d|j _|j jn|j rs|dk rcy|j j |Wqctk r_}zD|jtjkr#n*|jtjkrJ|jdk rJnWYdd}~XqcXn|j jn|jdk r|jj|j||jjrt|j|qn|j dk r|j j|j||j jrt|j|qnd}d}|jr?|j}|jjn|j ra|j }|j jn|dk rz|d}n|dk r|d}n||fS)N _stdout_bufftargetrFT _stderr_buffr)rhrrrZThreadrZ stdout_threadZdaemonstartr|rZ stderr_threadrjrrrrrrlrrtrZis_aliverrF)rrirrrrhr|r r r rsZ              zPopen._communicatecCs|jdk rdS|tjkr/|jne|tjkrWtj|jtjn=|tjkrtj|jtjnt dj |dS)zSend a signal to the process.NzUnsupported signal: {}) r signalSIGTERM terminateZ CTRL_C_EVENTrrbrZCTRL_BREAK_EVENTr2r)rsigr r r send_signals zPopen.send_signalc Css|jdk rdSytj|jdWnBtk rntj|j}|tjkran||_YnXdS)zTerminates the process.NrA)r r5ZTerminateProcessrPermissionErrorrZ STILL_ACTIVE)rrcr r r rs zPopen.terminatec Csd\}}d\}}d \}} |dkr3n`|tkrTtj\}}n?|tkro|j}n$t|tr|}n |j}|dkrn`|tkrtj\}}n?|tkr|j}n$t|tr|}n |j}|dkrnu|tkr2tj\}} nT|tkrG|} n?|tkrb|j} n$t|trz|} n |j} |||||| fS) z|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite rANr~r~)r~r~r~r~)r~r~r~r~)r~r~) rrpiper$rrr1rr) rrjrhr|rrrrrrr r r rsF                    cCsid}x=t|D]/}||krtj|||d}qqW|tkretj|tndS)NrCrA)sortedr closerangeMAXFD)r fds_to_keepZstart_fdrr r r _close_fds.s  zPopen._close_fdsc'(st|ttfr!|g}n t|}| rYddg|}rY|dpsz'Popen._execute_child..TrrAiP:rBsSubprocessError0sBad exception data from child: asciierrors surrogatepassZnoexecrqz: r~r~r~r~r~r~)*rrbyteslistrrr^duprr[rr2rdirnametuple get_exec_pathsetadd_posixsubprocessZ fork_execrrrr\r bytearrayrGrrrwaitpidrrECHILDsplitreprbuiltinsrr issubclassr1strerrorENOENT)'rrFrrrrrrrrrzrrrrrrrrZorig_executableZ errpipe_readZ errpipe_writeZlow_fds_to_closeZlow_fdZenv_listkrTZexecutable_listrZ devnull_fdZ errpipe_datapartrZexception_nameZ hex_errnoZerr_msgZchild_exception_typeZ errno_numZchild_exec_never_calledr )rr r8s         %     $$$          cCsM||r|| |_n*||r=|||_n tddS)z:All callers to this function MUST hold self._waitpid_lock.zUnknown child exit status!N)r r)rrZ _WIFSIGNALEDZ _WTERMSIGZ _WIFEXITEDZ _WEXITSTATUSr r r _handle_exitstatuss   zPopen._handle_exitstatuscCs|jdkr|jjds%dSzyQ|jdk rA|jS||j|\}}||jkrx|j|nWnXtk r}z8|dk r||_n|j|krd|_nWYdd}~XnXWd|jjXn|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)rr9Z_waitpidZ_WNOHANGZ_ECHILDrrrr r r r;s   #cCs{y"ttj|j|\}}WnLtk rp}z,|jtjkrOn|j}d}WYdd}~XnX||fS)z:All callers to this function MUST hold self._waitpid_lock.rN)rGrrrrrr)rZ wait_flagsrrrr r r _try_waits" zPopen._try_waitc Cs|jdk r|jS|dk s.|dk rk|dkrJt|}qk|dkrk|j|}qkn|dk rOd}x<|jjdrzO|jdk rPn|jtj\}}||jkr|j |PnWd|jj Xn|j|}|dkr%t |j |nt |d|d}tj|qWnmxj|jdkr|jL|jdk r~Pn|jd\}}||jkr|j |nWdQXqRW|jS)zOWait for child process to terminate. Returns returncode attribute.NgMb@?FrrBg?)r rrrr r rWNOHANGrr r rrFminrZsleep)rrrZdelayrrZ remainingr r r ras@      cCs|jr9|j r9|jj|s9|jjq9nd}d}|jsi|_|jrsg|j|jrr<platformrrrrrrrrrr ImportError Exceptionrr rrrr5rrrrZdummy_threadingr\rrrrZSelectSelector__all__r%r&r'r(r)r*r+r,rsr1r-sysconfrr:r@rrr$rGr`rr r#ryr!r"objectrrr r r r Ysx                  :      ; I