Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2....
File: subprocess.py
# subprocess - Subprocesses with accessible I/O streams
[0] Fix | Delete
#
[1] Fix | Delete
# For more information about this module, see PEP 324.
[2] Fix | Delete
#
[3] Fix | Delete
# Copyright (c) 2003-2005 by Peter Astrand <astrand@lysator.liu.se>
[4] Fix | Delete
#
[5] Fix | Delete
# Licensed to PSF under a Contributor Agreement.
[6] Fix | Delete
# See http://www.python.org/2.4/license for licensing details.
[7] Fix | Delete
[8] Fix | Delete
r"""Subprocesses with accessible I/O streams
[9] Fix | Delete
[10] Fix | Delete
This module allows you to spawn processes, connect to their
[11] Fix | Delete
input/output/error pipes, and obtain their return codes.
[12] Fix | Delete
[13] Fix | Delete
For a complete description of this module see the Python documentation.
[14] Fix | Delete
[15] Fix | Delete
Main API
[16] Fix | Delete
========
[17] Fix | Delete
call(...): Runs a command, waits for it to complete, then returns
[18] Fix | Delete
the return code.
[19] Fix | Delete
check_call(...): Same as call() but raises CalledProcessError()
[20] Fix | Delete
if return code is not 0
[21] Fix | Delete
check_output(...): Same as check_call() but returns the contents of
[22] Fix | Delete
stdout instead of a return code
[23] Fix | Delete
Popen(...): A class for flexibly executing a command in a new process
[24] Fix | Delete
[25] Fix | Delete
Constants
[26] Fix | Delete
---------
[27] Fix | Delete
PIPE: Special value that indicates a pipe should be created
[28] Fix | Delete
STDOUT: Special value that indicates that stderr should go to stdout
[29] Fix | Delete
"""
[30] Fix | Delete
[31] Fix | Delete
import sys
[32] Fix | Delete
mswindows = (sys.platform == "win32")
[33] Fix | Delete
[34] Fix | Delete
import os
[35] Fix | Delete
import types
[36] Fix | Delete
import traceback
[37] Fix | Delete
import gc
[38] Fix | Delete
import signal
[39] Fix | Delete
import errno
[40] Fix | Delete
[41] Fix | Delete
# Exception classes used by this module.
[42] Fix | Delete
class CalledProcessError(Exception):
[43] Fix | Delete
"""This exception is raised when a process run by check_call() or
[44] Fix | Delete
check_output() returns a non-zero exit status.
[45] Fix | Delete
[46] Fix | Delete
Attributes:
[47] Fix | Delete
cmd, returncode, output
[48] Fix | Delete
"""
[49] Fix | Delete
def __init__(self, returncode, cmd, output=None):
[50] Fix | Delete
self.returncode = returncode
[51] Fix | Delete
self.cmd = cmd
[52] Fix | Delete
self.output = output
[53] Fix | Delete
def __str__(self):
[54] Fix | Delete
return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
[55] Fix | Delete
[56] Fix | Delete
[57] Fix | Delete
if mswindows:
[58] Fix | Delete
import threading
[59] Fix | Delete
import msvcrt
[60] Fix | Delete
import _subprocess
[61] Fix | Delete
class STARTUPINFO:
[62] Fix | Delete
dwFlags = 0
[63] Fix | Delete
hStdInput = None
[64] Fix | Delete
hStdOutput = None
[65] Fix | Delete
hStdError = None
[66] Fix | Delete
wShowWindow = 0
[67] Fix | Delete
class pywintypes:
[68] Fix | Delete
error = IOError
[69] Fix | Delete
else:
[70] Fix | Delete
import select
[71] Fix | Delete
_has_poll = hasattr(select, 'poll')
[72] Fix | Delete
try:
[73] Fix | Delete
import threading
[74] Fix | Delete
except ImportError:
[75] Fix | Delete
threading = None
[76] Fix | Delete
import fcntl
[77] Fix | Delete
import pickle
[78] Fix | Delete
[79] Fix | Delete
# When select or poll has indicated that the file is writable,
[80] Fix | Delete
# we can write up to _PIPE_BUF bytes without risk of blocking.
[81] Fix | Delete
# POSIX defines PIPE_BUF as >= 512.
[82] Fix | Delete
_PIPE_BUF = getattr(select, 'PIPE_BUF', 512)
[83] Fix | Delete
[84] Fix | Delete
[85] Fix | Delete
__all__ = ["Popen", "PIPE", "STDOUT", "call", "check_call",
[86] Fix | Delete
"check_output", "CalledProcessError"]
[87] Fix | Delete
[88] Fix | Delete
if mswindows:
[89] Fix | Delete
from _subprocess import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
[90] Fix | Delete
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
[91] Fix | Delete
STD_ERROR_HANDLE, SW_HIDE,
[92] Fix | Delete
STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW)
[93] Fix | Delete
[94] Fix | Delete
__all__.extend(["CREATE_NEW_CONSOLE", "CREATE_NEW_PROCESS_GROUP",
[95] Fix | Delete
"STD_INPUT_HANDLE", "STD_OUTPUT_HANDLE",
[96] Fix | Delete
"STD_ERROR_HANDLE", "SW_HIDE",
[97] Fix | Delete
"STARTF_USESTDHANDLES", "STARTF_USESHOWWINDOW"])
[98] Fix | Delete
try:
[99] Fix | Delete
MAXFD = os.sysconf("SC_OPEN_MAX")
[100] Fix | Delete
except:
[101] Fix | Delete
MAXFD = 256
[102] Fix | Delete
[103] Fix | Delete
_active = []
[104] Fix | Delete
[105] Fix | Delete
def _cleanup():
[106] Fix | Delete
for inst in _active[:]:
[107] Fix | Delete
res = inst._internal_poll(_deadstate=sys.maxint)
[108] Fix | Delete
if res is not None:
[109] Fix | Delete
try:
[110] Fix | Delete
_active.remove(inst)
[111] Fix | Delete
except ValueError:
[112] Fix | Delete
# This can happen if two threads create a new Popen instance.
[113] Fix | Delete
# It's harmless that it was already removed, so ignore.
[114] Fix | Delete
pass
[115] Fix | Delete
[116] Fix | Delete
PIPE = -1
[117] Fix | Delete
STDOUT = -2
[118] Fix | Delete
[119] Fix | Delete
[120] Fix | Delete
def _eintr_retry_call(func, *args):
[121] Fix | Delete
while True:
[122] Fix | Delete
try:
[123] Fix | Delete
return func(*args)
[124] Fix | Delete
except (OSError, IOError) as e:
[125] Fix | Delete
if e.errno == errno.EINTR:
[126] Fix | Delete
continue
[127] Fix | Delete
raise
[128] Fix | Delete
[129] Fix | Delete
[130] Fix | Delete
# XXX This function is only used by multiprocessing and the test suite,
[131] Fix | Delete
# but it's here so that it can be imported when Python is compiled without
[132] Fix | Delete
# threads.
[133] Fix | Delete
[134] Fix | Delete
def _args_from_interpreter_flags():
[135] Fix | Delete
"""Return a list of command-line arguments reproducing the current
[136] Fix | Delete
settings in sys.flags and sys.warnoptions."""
[137] Fix | Delete
flag_opt_map = {
[138] Fix | Delete
'debug': 'd',
[139] Fix | Delete
# 'inspect': 'i',
[140] Fix | Delete
# 'interactive': 'i',
[141] Fix | Delete
'optimize': 'O',
[142] Fix | Delete
'dont_write_bytecode': 'B',
[143] Fix | Delete
'no_user_site': 's',
[144] Fix | Delete
'no_site': 'S',
[145] Fix | Delete
'ignore_environment': 'E',
[146] Fix | Delete
'verbose': 'v',
[147] Fix | Delete
'bytes_warning': 'b',
[148] Fix | Delete
'py3k_warning': '3',
[149] Fix | Delete
}
[150] Fix | Delete
args = []
[151] Fix | Delete
for flag, opt in flag_opt_map.items():
[152] Fix | Delete
v = getattr(sys.flags, flag)
[153] Fix | Delete
if v > 0:
[154] Fix | Delete
args.append('-' + opt * v)
[155] Fix | Delete
if getattr(sys.flags, 'hash_randomization') != 0:
[156] Fix | Delete
args.append('-R')
[157] Fix | Delete
for opt in sys.warnoptions:
[158] Fix | Delete
args.append('-W' + opt)
[159] Fix | Delete
return args
[160] Fix | Delete
[161] Fix | Delete
[162] Fix | Delete
def call(*popenargs, **kwargs):
[163] Fix | Delete
"""Run command with arguments. Wait for command to complete, then
[164] Fix | Delete
return the returncode attribute.
[165] Fix | Delete
[166] Fix | Delete
The arguments are the same as for the Popen constructor. Example:
[167] Fix | Delete
[168] Fix | Delete
retcode = call(["ls", "-l"])
[169] Fix | Delete
"""
[170] Fix | Delete
return Popen(*popenargs, **kwargs).wait()
[171] Fix | Delete
[172] Fix | Delete
[173] Fix | Delete
def check_call(*popenargs, **kwargs):
[174] Fix | Delete
"""Run command with arguments. Wait for command to complete. If
[175] Fix | Delete
the exit code was zero then return, otherwise raise
[176] Fix | Delete
CalledProcessError. The CalledProcessError object will have the
[177] Fix | Delete
return code in the returncode attribute.
[178] Fix | Delete
[179] Fix | Delete
The arguments are the same as for the Popen constructor. Example:
[180] Fix | Delete
[181] Fix | Delete
check_call(["ls", "-l"])
[182] Fix | Delete
"""
[183] Fix | Delete
retcode = call(*popenargs, **kwargs)
[184] Fix | Delete
if retcode:
[185] Fix | Delete
cmd = kwargs.get("args")
[186] Fix | Delete
if cmd is None:
[187] Fix | Delete
cmd = popenargs[0]
[188] Fix | Delete
raise CalledProcessError(retcode, cmd)
[189] Fix | Delete
return 0
[190] Fix | Delete
[191] Fix | Delete
[192] Fix | Delete
def check_output(*popenargs, **kwargs):
[193] Fix | Delete
r"""Run command with arguments and return its output as a byte string.
[194] Fix | Delete
[195] Fix | Delete
If the exit code was non-zero it raises a CalledProcessError. The
[196] Fix | Delete
CalledProcessError object will have the return code in the returncode
[197] Fix | Delete
attribute and output in the output attribute.
[198] Fix | Delete
[199] Fix | Delete
The arguments are the same as for the Popen constructor. Example:
[200] Fix | Delete
[201] Fix | Delete
>>> check_output(["ls", "-l", "/dev/null"])
[202] Fix | Delete
'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
[203] Fix | Delete
[204] Fix | Delete
The stdout argument is not allowed as it is used internally.
[205] Fix | Delete
To capture standard error in the result, use stderr=STDOUT.
[206] Fix | Delete
[207] Fix | Delete
>>> check_output(["/bin/sh", "-c",
[208] Fix | Delete
... "ls -l non_existent_file ; exit 0"],
[209] Fix | Delete
... stderr=STDOUT)
[210] Fix | Delete
'ls: non_existent_file: No such file or directory\n'
[211] Fix | Delete
"""
[212] Fix | Delete
if 'stdout' in kwargs:
[213] Fix | Delete
raise ValueError('stdout argument not allowed, it will be overridden.')
[214] Fix | Delete
process = Popen(stdout=PIPE, *popenargs, **kwargs)
[215] Fix | Delete
output, unused_err = process.communicate()
[216] Fix | Delete
retcode = process.poll()
[217] Fix | Delete
if retcode:
[218] Fix | Delete
cmd = kwargs.get("args")
[219] Fix | Delete
if cmd is None:
[220] Fix | Delete
cmd = popenargs[0]
[221] Fix | Delete
raise CalledProcessError(retcode, cmd, output=output)
[222] Fix | Delete
return output
[223] Fix | Delete
[224] Fix | Delete
[225] Fix | Delete
def list2cmdline(seq):
[226] Fix | Delete
"""
[227] Fix | Delete
Translate a sequence of arguments into a command line
[228] Fix | Delete
string, using the same rules as the MS C runtime:
[229] Fix | Delete
[230] Fix | Delete
1) Arguments are delimited by white space, which is either a
[231] Fix | Delete
space or a tab.
[232] Fix | Delete
[233] Fix | Delete
2) A string surrounded by double quotation marks is
[234] Fix | Delete
interpreted as a single argument, regardless of white space
[235] Fix | Delete
contained within. A quoted string can be embedded in an
[236] Fix | Delete
argument.
[237] Fix | Delete
[238] Fix | Delete
3) A double quotation mark preceded by a backslash is
[239] Fix | Delete
interpreted as a literal double quotation mark.
[240] Fix | Delete
[241] Fix | Delete
4) Backslashes are interpreted literally, unless they
[242] Fix | Delete
immediately precede a double quotation mark.
[243] Fix | Delete
[244] Fix | Delete
5) If backslashes immediately precede a double quotation mark,
[245] Fix | Delete
every pair of backslashes is interpreted as a literal
[246] Fix | Delete
backslash. If the number of backslashes is odd, the last
[247] Fix | Delete
backslash escapes the next double quotation mark as
[248] Fix | Delete
described in rule 3.
[249] Fix | Delete
"""
[250] Fix | Delete
[251] Fix | Delete
# See
[252] Fix | Delete
# http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
[253] Fix | Delete
# or search http://msdn.microsoft.com for
[254] Fix | Delete
# "Parsing C++ Command-Line Arguments"
[255] Fix | Delete
result = []
[256] Fix | Delete
needquote = False
[257] Fix | Delete
for arg in seq:
[258] Fix | Delete
bs_buf = []
[259] Fix | Delete
[260] Fix | Delete
# Add a space to separate this argument from the others
[261] Fix | Delete
if result:
[262] Fix | Delete
result.append(' ')
[263] Fix | Delete
[264] Fix | Delete
needquote = (" " in arg) or ("\t" in arg) or not arg
[265] Fix | Delete
if needquote:
[266] Fix | Delete
result.append('"')
[267] Fix | Delete
[268] Fix | Delete
for c in arg:
[269] Fix | Delete
if c == '\\':
[270] Fix | Delete
# Don't know if we need to double yet.
[271] Fix | Delete
bs_buf.append(c)
[272] Fix | Delete
elif c == '"':
[273] Fix | Delete
# Double backslashes.
[274] Fix | Delete
result.append('\\' * len(bs_buf)*2)
[275] Fix | Delete
bs_buf = []
[276] Fix | Delete
result.append('\\"')
[277] Fix | Delete
else:
[278] Fix | Delete
# Normal char
[279] Fix | Delete
if bs_buf:
[280] Fix | Delete
result.extend(bs_buf)
[281] Fix | Delete
bs_buf = []
[282] Fix | Delete
result.append(c)
[283] Fix | Delete
[284] Fix | Delete
# Add remaining backslashes, if any.
[285] Fix | Delete
if bs_buf:
[286] Fix | Delete
result.extend(bs_buf)
[287] Fix | Delete
[288] Fix | Delete
if needquote:
[289] Fix | Delete
result.extend(bs_buf)
[290] Fix | Delete
result.append('"')
[291] Fix | Delete
[292] Fix | Delete
return ''.join(result)
[293] Fix | Delete
[294] Fix | Delete
[295] Fix | Delete
class Popen(object):
[296] Fix | Delete
""" Execute a child program in a new process.
[297] Fix | Delete
[298] Fix | Delete
For a complete description of the arguments see the Python documentation.
[299] Fix | Delete
[300] Fix | Delete
Arguments:
[301] Fix | Delete
args: A string, or a sequence of program arguments.
[302] Fix | Delete
[303] Fix | Delete
bufsize: supplied as the buffering argument to the open() function when
[304] Fix | Delete
creating the stdin/stdout/stderr pipe file objects
[305] Fix | Delete
[306] Fix | Delete
executable: A replacement program to execute.
[307] Fix | Delete
[308] Fix | Delete
stdin, stdout and stderr: These specify the executed programs' standard
[309] Fix | Delete
input, standard output and standard error file handles, respectively.
[310] Fix | Delete
[311] Fix | Delete
preexec_fn: (POSIX only) An object to be called in the child process
[312] Fix | Delete
just before the child is executed.
[313] Fix | Delete
[314] Fix | Delete
close_fds: Controls closing or inheriting of file descriptors.
[315] Fix | Delete
[316] Fix | Delete
shell: If true, the command will be executed through the shell.
[317] Fix | Delete
[318] Fix | Delete
cwd: Sets the current directory before the child is executed.
[319] Fix | Delete
[320] Fix | Delete
env: Defines the environment variables for the new process.
[321] Fix | Delete
[322] Fix | Delete
universal_newlines: If true, use universal line endings for file
[323] Fix | Delete
objects stdin, stdout and stderr.
[324] Fix | Delete
[325] Fix | Delete
startupinfo and creationflags (Windows only)
[326] Fix | Delete
[327] Fix | Delete
Attributes:
[328] Fix | Delete
stdin, stdout, stderr, pid, returncode
[329] Fix | Delete
"""
[330] Fix | Delete
_child_created = False # Set here since __del__ checks it
[331] Fix | Delete
[332] Fix | Delete
def __init__(self, args, bufsize=0, executable=None,
[333] Fix | Delete
stdin=None, stdout=None, stderr=None,
[334] Fix | Delete
preexec_fn=None, close_fds=False, shell=False,
[335] Fix | Delete
cwd=None, env=None, universal_newlines=False,
[336] Fix | Delete
startupinfo=None, creationflags=0):
[337] Fix | Delete
"""Create new Popen instance."""
[338] Fix | Delete
_cleanup()
[339] Fix | Delete
[340] Fix | Delete
if not isinstance(bufsize, (int, long)):
[341] Fix | Delete
raise TypeError("bufsize must be an integer")
[342] Fix | Delete
[343] Fix | Delete
if mswindows:
[344] Fix | Delete
if preexec_fn is not None:
[345] Fix | Delete
raise ValueError("preexec_fn is not supported on Windows "
[346] Fix | Delete
"platforms")
[347] Fix | Delete
if close_fds and (stdin is not None or stdout is not None or
[348] Fix | Delete
stderr is not None):
[349] Fix | Delete
raise ValueError("close_fds is not supported on Windows "
[350] Fix | Delete
"platforms if you redirect stdin/stdout/stderr")
[351] Fix | Delete
else:
[352] Fix | Delete
# POSIX
[353] Fix | Delete
if startupinfo is not None:
[354] Fix | Delete
raise ValueError("startupinfo is only supported on Windows "
[355] Fix | Delete
"platforms")
[356] Fix | Delete
if creationflags != 0:
[357] Fix | Delete
raise ValueError("creationflags is only supported on Windows "
[358] Fix | Delete
"platforms")
[359] Fix | Delete
[360] Fix | Delete
self.stdin = None
[361] Fix | Delete
self.stdout = None
[362] Fix | Delete
self.stderr = None
[363] Fix | Delete
self.pid = None
[364] Fix | Delete
self.returncode = None
[365] Fix | Delete
self.universal_newlines = universal_newlines
[366] Fix | Delete
[367] Fix | Delete
# Input and output objects. The general principle is like
[368] Fix | Delete
# this:
[369] Fix | Delete
#
[370] Fix | Delete
# Parent Child
[371] Fix | Delete
# ------ -----
[372] Fix | Delete
# p2cwrite ---stdin---> p2cread
[373] Fix | Delete
# c2pread <--stdout--- c2pwrite
[374] Fix | Delete
# errread <--stderr--- errwrite
[375] Fix | Delete
#
[376] Fix | Delete
# On POSIX, the child objects are file descriptors. On
[377] Fix | Delete
# Windows, these are Windows file handles. The parent objects
[378] Fix | Delete
# are file descriptors on both platforms. The parent objects
[379] Fix | Delete
# are None when not using PIPEs. The child objects are None
[380] Fix | Delete
# when not redirecting.
[381] Fix | Delete
[382] Fix | Delete
(p2cread, p2cwrite,
[383] Fix | Delete
c2pread, c2pwrite,
[384] Fix | Delete
errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr)
[385] Fix | Delete
[386] Fix | Delete
try:
[387] Fix | Delete
self._execute_child(args, executable, preexec_fn, close_fds,
[388] Fix | Delete
cwd, env, universal_newlines,
[389] Fix | Delete
startupinfo, creationflags, shell, to_close,
[390] Fix | Delete
p2cread, p2cwrite,
[391] Fix | Delete
c2pread, c2pwrite,
[392] Fix | Delete
errread, errwrite)
[393] Fix | Delete
except Exception:
[394] Fix | Delete
# Preserve original exception in case os.close raises.
[395] Fix | Delete
exc_type, exc_value, exc_trace = sys.exc_info()
[396] Fix | Delete
[397] Fix | Delete
for fd in to_close:
[398] Fix | Delete
try:
[399] Fix | Delete
if mswindows:
[400] Fix | Delete
fd.Close()
[401] Fix | Delete
else:
[402] Fix | Delete
os.close(fd)
[403] Fix | Delete
except EnvironmentError:
[404] Fix | Delete
pass
[405] Fix | Delete
[406] Fix | Delete
raise exc_type, exc_value, exc_trace
[407] Fix | Delete
[408] Fix | Delete
if mswindows:
[409] Fix | Delete
if p2cwrite is not None:
[410] Fix | Delete
p2cwrite = msvcrt.open_osfhandle(p2cwrite.Detach(), 0)
[411] Fix | Delete
if c2pread is not None:
[412] Fix | Delete
c2pread = msvcrt.open_osfhandle(c2pread.Detach(), 0)
[413] Fix | Delete
if errread is not None:
[414] Fix | Delete
errread = msvcrt.open_osfhandle(errread.Detach(), 0)
[415] Fix | Delete
[416] Fix | Delete
if p2cwrite is not None:
[417] Fix | Delete
self.stdin = os.fdopen(p2cwrite, 'wb', bufsize)
[418] Fix | Delete
if c2pread is not None:
[419] Fix | Delete
if universal_newlines:
[420] Fix | Delete
self.stdout = os.fdopen(c2pread, 'rU', bufsize)
[421] Fix | Delete
else:
[422] Fix | Delete
self.stdout = os.fdopen(c2pread, 'rb', bufsize)
[423] Fix | Delete
if errread is not None:
[424] Fix | Delete
if universal_newlines:
[425] Fix | Delete
self.stderr = os.fdopen(errread, 'rU', bufsize)
[426] Fix | Delete
else:
[427] Fix | Delete
self.stderr = os.fdopen(errread, 'rb', bufsize)
[428] Fix | Delete
[429] Fix | Delete
[430] Fix | Delete
def _translate_newlines(self, data):
[431] Fix | Delete
data = data.replace("\r\n", "\n")
[432] Fix | Delete
data = data.replace("\r", "\n")
[433] Fix | Delete
return data
[434] Fix | Delete
[435] Fix | Delete
[436] Fix | Delete
def __del__(self, _maxint=sys.maxint):
[437] Fix | Delete
# If __init__ hasn't had a chance to execute (e.g. if it
[438] Fix | Delete
# was passed an undeclared keyword argument), we don't
[439] Fix | Delete
# have a _child_created attribute at all.
[440] Fix | Delete
if not self._child_created:
[441] Fix | Delete
# We didn't get to successfully create a child process.
[442] Fix | Delete
return
[443] Fix | Delete
# In case the child hasn't been waited on, check if it's done.
[444] Fix | Delete
self._internal_poll(_deadstate=_maxint)
[445] Fix | Delete
if self.returncode is None and _active is not None:
[446] Fix | Delete
# Child is still running, keep us alive until we can wait on it.
[447] Fix | Delete
_active.append(self)
[448] Fix | Delete
[449] Fix | Delete
[450] Fix | Delete
def communicate(self, input=None):
[451] Fix | Delete
"""Interact with process: Send data to stdin. Read data from
[452] Fix | Delete
stdout and stderr, until end-of-file is reached. Wait for
[453] Fix | Delete
process to terminate. The optional input argument should be a
[454] Fix | Delete
string to be sent to the child process, or None, if no data
[455] Fix | Delete
should be sent to the child.
[456] Fix | Delete
[457] Fix | Delete
communicate() returns a tuple (stdout, stderr)."""
[458] Fix | Delete
[459] Fix | Delete
# Optimization: If we are only using one pipe, or no pipe at
[460] Fix | Delete
# all, using select() or threads is unnecessary.
[461] Fix | Delete
if [self.stdin, self.stdout, self.stderr].count(None) >= 2:
[462] Fix | Delete
stdout = None
[463] Fix | Delete
stderr = None
[464] Fix | Delete
if self.stdin:
[465] Fix | Delete
if input:
[466] Fix | Delete
try:
[467] Fix | Delete
self.stdin.write(input)
[468] Fix | Delete
except IOError as e:
[469] Fix | Delete
if e.errno != errno.EPIPE and e.errno != errno.EINVAL:
[470] Fix | Delete
raise
[471] Fix | Delete
self.stdin.close()
[472] Fix | Delete
elif self.stdout:
[473] Fix | Delete
stdout = _eintr_retry_call(self.stdout.read)
[474] Fix | Delete
self.stdout.close()
[475] Fix | Delete
elif self.stderr:
[476] Fix | Delete
stderr = _eintr_retry_call(self.stderr.read)
[477] Fix | Delete
self.stderr.close()
[478] Fix | Delete
self.wait()
[479] Fix | Delete
return (stdout, stderr)
[480] Fix | Delete
[481] Fix | Delete
return self._communicate(input)
[482] Fix | Delete
[483] Fix | Delete
[484] Fix | Delete
def poll(self):
[485] Fix | Delete
"""Check if child process has terminated. Set and return returncode
[486] Fix | Delete
attribute."""
[487] Fix | Delete
return self._internal_poll()
[488] Fix | Delete
[489] Fix | Delete
[490] Fix | Delete
if mswindows:
[491] Fix | Delete
#
[492] Fix | Delete
# Windows methods
[493] Fix | Delete
#
[494] Fix | Delete
def _get_handles(self, stdin, stdout, stderr):
[495] Fix | Delete
"""Construct and return tuple with IO objects:
[496] Fix | Delete
p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
[497] Fix | Delete
"""
[498] Fix | Delete
to_close = set()
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function