grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î   f%üã@s4dZddlZejdkZddlZddlZddlZddlZddlZddl Z ddl Z yddlm Z Wn"e k r­ddlmZ YnXGdd„deƒZGdd „d eƒZGd d „d eƒZer0ddlZddlZddlZGd d „d ƒZn‹ddlZddlZddlZyddlZWne k r„ddlZYnXeeddƒZeedƒr²ejZn 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"gƒGd#d$„d$e*ƒZ+nyej,d%ƒZ-Wnd&Z-YnXgZ.d'd(„Z/d9Z0d:Z1d;Z2d,d-„Z3d.d/„Z4d0dd1d„Z5d2d„Z6d0dd3d„Z7d4d5„Z8d6d„Z9d7d„Z:e;ƒZ<Gd8d„de;ƒ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"}) éNÚwin32)Ú monotonic)Útimec@seZdZdS)ÚSubprocessErrorN)Ú__name__Ú __module__Ú __qualname__©r r ú//opt/alt/python34/lib64/python3.4/subprocess.pyrks rc@s1eZdZdZddd„Zdd„ZdS)ÚCalledProcessErrorzýThis 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)Ú returncodeÚcmdÚoutput)Ú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@s1eZdZdZddd„Zdd„ZdS)ÚTimeoutExpiredz]This exception is raised when the timeout expires while waiting for a child process. NcCs||_||_||_dS)N)r Útimeoutr)rr rrr r r r€s  zTimeoutExpired.__init__cCsd|j|jfS)Nz'Command '%s' timed out after %s seconds)r r)rr r r r…szTimeoutExpired.__str__)rrrrrrr r r r r|s rc@s.eZdZdZdZdZdZdZdS)Ú STARTUPINFOrN)rrrÚdwFlagsÚ hStdInputÚ hStdOutputÚ hStdErrorÚ wShowWindowr r r r rŽs rZPIPE_BUFiÚ PollSelectorÚPopenÚPIPEÚSTDOUTÚcallÚ check_callÚgetstatusoutputÚ getoutputÚ check_outputÚDEVNULL)ÚCREATE_NEW_CONSOLEÚCREATE_NEW_PROCESS_GROUPÚSTD_INPUT_HANDLEÚSTD_OUTPUT_HANDLEÚSTD_ERROR_HANDLEÚSW_HIDEÚSTARTF_USESTDHANDLESÚSTARTF_USESHOWWINDOWr%r&r'r(r)r*r+r,c@sLeZdZdZejdd„Zdd„Zdd„ZeZ eZ dS) ÚHandleFcCs#|jsd|_||ƒndS)NT)Úclosed)rÚ CloseHandler r r ÚClose¼s  z Handle.ClosecCs,|jsd|_t|ƒStdƒ‚dS)NTzalready closed)r.ÚintÚ ValueError)rr r r ÚDetachÁs   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_MAXéc Csixbtdd…D]P}|jdtjƒ}|dk rytj|ƒWqatk r]YqaXqqWdS)NÚ _deadstate)Ú_activeÚ_internal_pollÚsysÚmaxsizeÚremover2)ZinstÚresr r r Ú_cleanupØs  r@éééc Gs1x*y||ŒSWqtk r(wYqXqWdS)N)ÚInterruptedError)ÚfuncÚargsr r r Ú_eintr_retry_callès  rGcCsÇi dd6dd6dd6dd6d d 6d d 6d d6dd6dd6}g}xP|jƒD]B\}}ttj|ƒ}|dkrX|jd||ƒqXqXWx"tjD]}|jd|ƒq¨W|S)znReturn a list of command-line arguments reproducing the current settings in sys.flags and sys.warnoptions.ÚdÚdebugÚOÚoptimizeÚBÚdont_write_bytecodeÚsÚ no_user_siteÚSÚno_siteÚEÚignore_environmentÚvÚverboseÚbÚ bytes_warningÚqÚquietrú-z-W)ÚitemsÚgetattrr<ÚflagsÚappendÚ warnoptions)Z flag_opt_maprFZflagZoptrTr r r Ú_args_from_interpreter_flagsôs$  r`rcOsRt||Ž�=}y|jd|ƒSWn|jƒ|jƒ‚YnXWdQXdS)zÞRun 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ÚwaitÚkill)rÚ popenargsÚkwargsÚpr 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)rÚgetr )rcrdÚretcoder r r r r s   cOs;d|krtdƒ‚nd|kr`d|krBtdƒ‚n|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.ÚinputÚstdinz/stdin and input arguments may not both be used.Nrr) r2rrÚ communicaterrbrFraÚpollr )rrcrdZ inputdataZprocessrZ unused_errrgr r r r#2s0          !cCsGg}d}x+|D]#}g}|r5|jdƒnd|kpQd|kpQ| }|rj|jdƒnx�|D]ˆ}|dkr“|j|ƒqq|dkrÐ|jdt|ƒdƒg}|jdƒqq|rì|j|ƒg}n|j|ƒqqW|r|j|ƒn|r|j|ƒ|jdƒqqWdj|ƒ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^ÚlenÚextendÚjoin)ÚseqÚresultZ needquoteÚargZbs_bufÚcr r r Ú list2cmdlinems4       rycCs•y(t|dddddtƒ}d}Wn7tk ra}z|j}|j}WYdd}~XnX|d d…dkr‹|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') ÚshellTÚuniversal_newlinesÚstderrrNrAÚ éÿÿÿÿ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=dddddeddddddddfdd„Zdd „Zd d „Zd d „Ze j dd„Z dd„Z dddd„Z dd„Zdd„Zdd„Zer\dd„Zdd„Zdd„Zdejejejd d!„Zddd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„ZeZnÃd,d„Zd-d.„Z d/d„Ze!j"e!j#e!j$e!j%d0d1„Z&de!j'e!j(e)j*d2d!„Zd3d4„Z+ddd5d#„Zd6d'„Zd7d8„Z,d9d)„Zd:d+„Zd;d<„ZdS)>rFrANrTcCs…tƒtjƒ|_d|_d|_|dkr=d}nt|tƒs[tdƒ‚nt râ|dk r|t dƒ‚n|dk p�|dk p�|dk }|t krÄ|r»d}qßd}qS|rS|rSt dƒ‚qSnq|t kr÷d}n|r| rt j dtƒd}n| dk r8t d ƒ‚n|d krSt d ƒ‚n||_d|_d|_d|_d|_d|_| |_|j|||ƒ\}}}}}}t r7|dkrætj|jƒd ƒ}n|dkr tj|jƒd ƒ}n|dkr7tj|jƒd ƒ}q7n|dkrŽtj|d |ƒ|_| rŽtj|jd dd|dkƒ|_qŽn|dkrÓtj|d|ƒ|_| rÓtj|jƒ|_qÓn|dkrtj|d|ƒ|_| rtj|jƒ|_qnd|_yD|j|||||| | | || ||||||||ƒWnxLtd|j|j|jfƒD])}y|j ƒWq�t!k rµYq�Xq�W|jsyg}|t"krå|j#|ƒn|t"kr|j#|ƒn|t"kr|j#|ƒnt$|dƒr?|j#|j%ƒnx7|D],}yt&j |ƒWqFt!k rqYqFXqFWn‚YnXdS)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 platformsÚwbZ write_throughÚline_bufferingÚrbÚ_devnullr~r~r~r~r~r~r~)'r@Ú threadingZLockÚ _waitpid_lockÚ_inputÚ_communication_startedÚ isinstancer1Ú TypeErrorÚ mswindowsr2Ú_PLATFORM_DEFAULT_CLOSE_FDSÚwarningsÚwarnÚRuntimeWarningrFrjrhr|Úpidr r{Ú _get_handlesÚmsvcrtZopen_osfhandler3ÚioÚopenÚ TextIOWrapperÚ_closed_child_pipe_fdsÚ_execute_childÚfilterÚcloseÚOSErrorrr^ÚhasattrrƒÚos)rrFÚbufsizeÚ executablerjrhr|Ú preexec_fnÚ close_fdsrzÚcwdÚenvr{Ú startupinfoÚ creationflagsÚrestore_signalsÚstart_new_sessionÚpass_fdsZ any_stdio_setÚp2creadÚp2cwriteÚc2preadÚc2pwriteÚerrreadÚerrwriteÚfZto_closeÚfdr r r rçs°                       '         (         zPopen.__init__cCs+|j|ƒ}|jddƒjddƒS)Nz r}ú )ÚdecodeÚreplace)rrÚencodingr r r Ú_translate_newlinestszPopen._translate_newlinescCs|S)Nr )rr r r Ú __enter__xszPopen.__enter__c Csa|jr|jjƒn|jr2|jjƒnz|jrN|jjƒnWd|jƒXdS)N)rhr˜r|rjra)rÚtypeÚvalueÚ tracebackr r r Ú__exit__{s   zPopen.__exit__cCsL|js dS|jd|ƒ|jdkrHtdk rHtj|ƒndS)Nr9)Ú_child_createdr;r r:r^)rZ_maxsizer r r r6‡s  z Popen.__del__cCs4t|dƒs-tjtjtjƒ|_n|jS)Nrƒ)ršr›r“ÚdevnullÚO_RDWRrƒ)rr r r Ú _get_devnull‘szPopen._get_devnullcCsÅ|jr|rtdƒ‚n|dkrR|j rR|j|j|jgjdƒdkrRd}d}|jrï|rßy|jj|ƒWqßtk rÛ}z/|jtj krÉ|jtj krÉ‚nWYdd}~XqßXn|jj ƒnV|jrt |jj ƒ}|jj ƒn+|jrEt |jj ƒ}|jj ƒn|jƒni|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)r‡r2rjrhr|ÚcountÚwriter™ÚerrnoÚEPIPEÚEINVALr˜rGÚreadraÚ_timeÚ _communicateÚ_remaining_time)rrirrhr|ÚeÚendtimeÚstsr r r rk–s: ' $     zPopen.communicatecCs |jƒS)N)r;)rr r r rlÈsz Popen.pollcCs|dkrdS|tƒSdS)z5Convenience for _communicate when computing timeouts.N)rÃ)rrÇr r r rÅÌs zPopen._remaining_timecCs8|dkrdStƒ|kr4t|j|ƒ‚ndS)z2Convenience for checking if a timeout has expired.N)rÃrrF)rrÇÚ orig_timeoutr r r Ú_check_timeoutÔs zPopen._check_timeoutc Cs•|dkr(|dkr(|dkr(d Sd \}}d\}}d\}} |dkr­tjtjƒ}|dkrGtjddƒ\}} t|ƒ}tj| ƒqGnš|tkrítjddƒ\}}t|ƒt|ƒ}}nZ|tkrtj |j ƒƒ}n6t |t ƒr2tj |ƒ}ntj |j ƒƒ}|j|ƒ}|dkr·tjtjƒ}|dkrQtjddƒ\} }t|ƒ}tj| ƒqQnš|tkr÷tjddƒ\}}t|ƒt|ƒ}}nZ|tkrtj |j ƒƒ}n6t |t ƒr<tj |ƒ}ntj |j ƒƒ}|j|ƒ}|dkrÁtjtjƒ} | 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$r‘Z get_osfhandler¼rˆr1ÚfilenoÚ_make_inheritabler(r)r) rrjrhr|r§r¨r©rªr«r¬Ú_r r r r�àsn$                    zPopen._get_handlescCs7tjtjƒ|tjƒddtjƒ}t|ƒS)z2Return a duplicate of handle, which is inheritablerrA)r5ZDuplicateHandleZGetCurrentProcessZDUPLICATE_SAME_ACCESSr-)rZhandleÚhr r r rÌ(s   zPopen._make_inheritablecCs½| stdƒ‚t|tƒs1t|ƒ}n|dkrItƒ}nd | ||fkrŽ|jtjO_| |_||_ ||_ n| rÜ|jtj O_tj |_ tjjddƒ}dj||ƒ}nz>tj||ddt| ƒ| |||ƒ \}}}}Wd| d kr6| jƒn|d krO|jƒn|d krh|jƒnt|dƒrŠtj|jƒnXd|_t|ƒ|_||_tj|ƒdS) z$Execute program (MS Windows version)z"pass_fds not supported on Windows.NrAZCOMSPECzcmd.exez {} /c "{}"rƒTr~r~r~r~)ÚAssertionErrorrˆÚstrryrrr5r+rrrr,r*rr›ÚenvironrfÚformatZ CreateProcessr1r0ršr˜rƒr¹r-Ú_handler�r/)rrFr�ržrŸr¦r r¡r¢r£rzr§r¨r©rªr«r¬Zunused_restore_signalsZunused_start_new_sessionZcomspecZhpZhtr�Útidr r r r–1sF                 zPopen._execute_childcCsF|jdkr?||jdƒ|kr?||jƒ|_q?n|jS)zÎCheck 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ƒ}|jdkr¦tj|j|ƒ}|tjkrŽt|j |ƒ‚ntj |jƒ|_n|jS)zOWait for child process to terminate. Returns returncode attribute.Niè) rÅr5ZINFINITEr1r ÚWaitForSingleObjectrÓZ WAIT_TIMEOUTrrFÚGetExitCodeProcess)rrrÇZtimeout_millisrvr r r ras     z Popen.waitcCs!|j|jƒƒ|jƒdS)N)r^rÂr˜)rZfhÚbufferr r r Ú _readerthread‘szPopen._readerthreadcCs�|jrht|dƒ rhg|_tjd|jd|j|jfƒ|_d|j_|jjƒn|j rÐt|dƒ rÐg|_ tjd|jd|j |j fƒ|_ d|j _|j jƒn|j rs|dk rcy|j j |ƒWqctk r_}zD|jtjkr#n*|jtjkrJ|jƒdk rJn‚WYdd}~XqcXn|j jƒn|jdk rÂ|jj|j|ƒƒ|jjƒrÂt|j|ƒ‚qÂn|j dk r|j j|j|ƒƒ|j jƒrt|j|ƒ‚qnd}d}|jr?|j}|jjƒn|j ra|j }|j jƒn|dk rz|d}n|dk r“|d}n||fS)NÚ _stdout_buffÚtargetrFTÚ _stderr_buffr)rhršrÙr„ZThreadrØZ stdout_threadZdaemonÚstartr|rÛZ stderr_threadrjr¾r™r¿rÀrÁrlr˜rtrÅZis_aliverrF)rrirÇrÉrÆrhr|r r r rÄ–sZ              zPopen._communicatecCs˜|jdk rdS|tjkr/|jƒne|tjkrWtj|jtjƒn=|tjkrtj|jtjƒnt dj |ƒƒ‚dS)zSend a signal to the process.NzUnsupported signal: {}) r ÚsignalÚSIGTERMÚ terminateZ CTRL_C_EVENTr›rbr�ZCTRL_BREAK_EVENTr2rÒ)rÚsigr r r Ú send_signalØs zPopen.send_signalc Css|jdk rdSytj|jdƒWnBtk rntj|jƒ}|tjkra‚n||_YnXdS)zTerminates the process.NrA)r r5ZTerminateProcessrÓÚPermissionErrorrÖZ STILL_ACTIVE)rÚrcr r r rßæs zPopen.terminatec Csœd\}}d\}}d \}} |dkr3n`|tkrTtjƒ\}}n?|tkro|jƒ}n$t|tƒr‡|}n |jƒ}|dkr¢n`|tkrÃtjƒ\}}n?|tkrÞ|jƒ}n$t|tƒrö|}n |jƒ}|dkrnu|tkr2tjƒ\}} nT|tkrG|} n?|tkrb|jƒ} n$t|tƒrz|} 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~) rr›Úpiper$r¼rˆr1rËr) rrjrhr|r§r¨r©rªr«r¬r r r r�ûsF                    cCsid}x=t|ƒD]/}||krtj||ƒ|d}qqW|tkretj|tƒndS)NrCrA)Úsortedr›Ú closerangeÚMAXFD)rÚ fds_to_keepZstart_fdr®r r r Ú _close_fds.s  zPopen._close_fdsc'(st|ttfƒr!|g}n t|ƒ}| rYddg|}ˆrYˆ|dpsz'Popen._execute_child..TrƒrAiPÃó:rBsSubprocessErroró0sBad exception data from child: ÚasciiÚerrorsÚ surrogatepasséZnoexecrqz: r~r~r~r~r~r~)*rˆrÐÚbytesÚlistr›rär^Údupr˜r[rìr2rëÚdirnameÚtupleÚ get_exec_pathÚsetÚaddÚ_posixsubprocessZ fork_execrår�r¹r\r•Ú bytearrayrGrÂrrÚwaitpidr™r¿ÚECHILDÚsplitÚreprÚbuiltinsr°rÚ issubclassr1ÚstrerrorÚENOENT)'rrFr�ržrŸr¦r r¡r¢r£rzr§r¨r©rªr«r¬r¤r¥Zorig_executableZ errpipe_readZ errpipe_writeZlow_fds_to_closeZlow_fdZenv_listÚkrTZexecutable_listrèZ devnull_fdZ errpipe_dataÚpartrÆZexception_nameZ hex_errnoZerr_msgZchild_exception_typeZ errno_numZchild_exec_never_calledr )r�r r–8s¶         %     $$$          cCsM||ƒr||ƒ |_n*||ƒr=||ƒ|_n tdƒ‚dS)z:All callers to this function MUST hold self._waitpid_lock.zUnknown child exit status!N)r r)rrÈZ _WIFSIGNALEDZ _WTERMSIGZ _WIFEXITEDZ _WEXITSTATUSr r r Ú_handle_exitstatus¼s   zPopen._handle_exitstatuscCsð|jdkré|jjdƒs%dSz°yQ|jdk rA|jS||j|ƒ\}}||jkrx|j|ƒnWnXtk rÓ}z8|dk r¦||_n|j|krÁd|_nWYdd}~XnXWd|jjƒXn|jS)zõCheck 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 r…Úacquirer�r r™r¿Úrelease)rr9Z_waitpidZ_WNOHANGZ_ECHILDr�rÈrÆr r r r;Ës   #cCs{y"ttj|j|ƒ\}}WnLtk rp}z,|jtjkrO‚n|j}d}WYdd}~XnX||fS)z:All callers to this function MUST hold self._waitpid_lock.rN)rGr›rr�r™r¿r)rZ wait_flagsr�rÈrÆr r r Ú _try_waitîs" zPopen._try_waitc Csä|jdk r|jS|dk s.|dk rk|dkrJtƒ|}qk|dkrk|j|ƒ}qkn|dk rpd}x]|jjdƒrzp|jdk r¨Pn|jtjƒ\}}||jksá|dksát ‚||jkr|j |ƒPnWd|jj ƒXn|j|ƒ}|dkrFt |j |ƒ‚nt|d|dƒ}tj|ƒq€Wnmxj|jdkrÜ|j�L|jdk rŸPn|jdƒ\}}||jkrÓ|j |ƒnWdQXqsW|jS)zOWait for child process to terminate. Returns returncode attribute.Ngü©ñÒMb@?FrrBgš™™™™™©?)r rÃrÅr…r r r›ÚWNOHANGr�rÏr r rrFÚminrZsleep)rrrÇZdelayr�rÈZ remainingr r r raýsB   !   cCs|jr9|j r9|jjƒ|s9|jjƒq9nd}d}|js’i|_|jrsg|j|jrr<ÚplatformrŠr’r›rrÝrrŒr¿rrÃÚ ImportErrorÚ Exceptionrr rr„r‘r5rrþrrZdummy_threadingr\rršrrZSelectSelectorÚ__all__r%r&r'r(r)r*r+r,rsr1r-Úsysconfrçr:r@rrr$rGr`rr r#ryr!r"Úobjectr‹rr r r r ÚYsx                  :      ; I