Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: subprocess.py
[1000] Fix | Delete
if shell:
[1001] Fix | Delete
startupinfo.dwFlags |= _winapi.STARTF_USESHOWWINDOW
[1002] Fix | Delete
startupinfo.wShowWindow = _winapi.SW_HIDE
[1003] Fix | Delete
comspec = os.environ.get("COMSPEC", "cmd.exe")
[1004] Fix | Delete
args = '{} /c "{}"'.format (comspec, args)
[1005] Fix | Delete
[1006] Fix | Delete
# Start the process
[1007] Fix | Delete
try:
[1008] Fix | Delete
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
[1009] Fix | Delete
# no special security
[1010] Fix | Delete
None, None,
[1011] Fix | Delete
int(not close_fds),
[1012] Fix | Delete
creationflags,
[1013] Fix | Delete
env,
[1014] Fix | Delete
os.fspath(cwd) if cwd is not None else None,
[1015] Fix | Delete
startupinfo)
[1016] Fix | Delete
finally:
[1017] Fix | Delete
# Child is launched. Close the parent's copy of those pipe
[1018] Fix | Delete
# handles that only the child should have open. You need
[1019] Fix | Delete
# to make sure that no handles to the write end of the
[1020] Fix | Delete
# output pipe are maintained in this process or else the
[1021] Fix | Delete
# pipe will not close when the child process exits and the
[1022] Fix | Delete
# ReadFile will hang.
[1023] Fix | Delete
if p2cread != -1:
[1024] Fix | Delete
p2cread.Close()
[1025] Fix | Delete
if c2pwrite != -1:
[1026] Fix | Delete
c2pwrite.Close()
[1027] Fix | Delete
if errwrite != -1:
[1028] Fix | Delete
errwrite.Close()
[1029] Fix | Delete
if hasattr(self, '_devnull'):
[1030] Fix | Delete
os.close(self._devnull)
[1031] Fix | Delete
# Prevent a double close of these handles/fds from __init__
[1032] Fix | Delete
# on error.
[1033] Fix | Delete
self._closed_child_pipe_fds = True
[1034] Fix | Delete
[1035] Fix | Delete
# Retain the process handle, but close the thread handle
[1036] Fix | Delete
self._child_created = True
[1037] Fix | Delete
self._handle = Handle(hp)
[1038] Fix | Delete
self.pid = pid
[1039] Fix | Delete
_winapi.CloseHandle(ht)
[1040] Fix | Delete
[1041] Fix | Delete
def _internal_poll(self, _deadstate=None,
[1042] Fix | Delete
_WaitForSingleObject=_winapi.WaitForSingleObject,
[1043] Fix | Delete
_WAIT_OBJECT_0=_winapi.WAIT_OBJECT_0,
[1044] Fix | Delete
_GetExitCodeProcess=_winapi.GetExitCodeProcess):
[1045] Fix | Delete
"""Check if child process has terminated. Returns returncode
[1046] Fix | Delete
attribute.
[1047] Fix | Delete
[1048] Fix | Delete
This method is called by __del__, so it can only refer to objects
[1049] Fix | Delete
in its local scope.
[1050] Fix | Delete
[1051] Fix | Delete
"""
[1052] Fix | Delete
if self.returncode is None:
[1053] Fix | Delete
if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
[1054] Fix | Delete
self.returncode = _GetExitCodeProcess(self._handle)
[1055] Fix | Delete
return self.returncode
[1056] Fix | Delete
[1057] Fix | Delete
[1058] Fix | Delete
def wait(self, timeout=None, endtime=None):
[1059] Fix | Delete
"""Wait for child process to terminate. Returns returncode
[1060] Fix | Delete
attribute."""
[1061] Fix | Delete
if endtime is not None:
[1062] Fix | Delete
warnings.warn(
[1063] Fix | Delete
"'endtime' argument is deprecated; use 'timeout'.",
[1064] Fix | Delete
DeprecationWarning,
[1065] Fix | Delete
stacklevel=2)
[1066] Fix | Delete
timeout = self._remaining_time(endtime)
[1067] Fix | Delete
if timeout is None:
[1068] Fix | Delete
timeout_millis = _winapi.INFINITE
[1069] Fix | Delete
else:
[1070] Fix | Delete
timeout_millis = int(timeout * 1000)
[1071] Fix | Delete
if self.returncode is None:
[1072] Fix | Delete
result = _winapi.WaitForSingleObject(self._handle,
[1073] Fix | Delete
timeout_millis)
[1074] Fix | Delete
if result == _winapi.WAIT_TIMEOUT:
[1075] Fix | Delete
raise TimeoutExpired(self.args, timeout)
[1076] Fix | Delete
self.returncode = _winapi.GetExitCodeProcess(self._handle)
[1077] Fix | Delete
return self.returncode
[1078] Fix | Delete
[1079] Fix | Delete
[1080] Fix | Delete
def _readerthread(self, fh, buffer):
[1081] Fix | Delete
buffer.append(fh.read())
[1082] Fix | Delete
fh.close()
[1083] Fix | Delete
[1084] Fix | Delete
[1085] Fix | Delete
def _communicate(self, input, endtime, orig_timeout):
[1086] Fix | Delete
# Start reader threads feeding into a list hanging off of this
[1087] Fix | Delete
# object, unless they've already been started.
[1088] Fix | Delete
if self.stdout and not hasattr(self, "_stdout_buff"):
[1089] Fix | Delete
self._stdout_buff = []
[1090] Fix | Delete
self.stdout_thread = \
[1091] Fix | Delete
threading.Thread(target=self._readerthread,
[1092] Fix | Delete
args=(self.stdout, self._stdout_buff))
[1093] Fix | Delete
self.stdout_thread.daemon = True
[1094] Fix | Delete
self.stdout_thread.start()
[1095] Fix | Delete
if self.stderr and not hasattr(self, "_stderr_buff"):
[1096] Fix | Delete
self._stderr_buff = []
[1097] Fix | Delete
self.stderr_thread = \
[1098] Fix | Delete
threading.Thread(target=self._readerthread,
[1099] Fix | Delete
args=(self.stderr, self._stderr_buff))
[1100] Fix | Delete
self.stderr_thread.daemon = True
[1101] Fix | Delete
self.stderr_thread.start()
[1102] Fix | Delete
[1103] Fix | Delete
if self.stdin:
[1104] Fix | Delete
self._stdin_write(input)
[1105] Fix | Delete
[1106] Fix | Delete
# Wait for the reader threads, or time out. If we time out, the
[1107] Fix | Delete
# threads remain reading and the fds left open in case the user
[1108] Fix | Delete
# calls communicate again.
[1109] Fix | Delete
if self.stdout is not None:
[1110] Fix | Delete
self.stdout_thread.join(self._remaining_time(endtime))
[1111] Fix | Delete
if self.stdout_thread.is_alive():
[1112] Fix | Delete
raise TimeoutExpired(self.args, orig_timeout)
[1113] Fix | Delete
if self.stderr is not None:
[1114] Fix | Delete
self.stderr_thread.join(self._remaining_time(endtime))
[1115] Fix | Delete
if self.stderr_thread.is_alive():
[1116] Fix | Delete
raise TimeoutExpired(self.args, orig_timeout)
[1117] Fix | Delete
[1118] Fix | Delete
# Collect the output from and close both pipes, now that we know
[1119] Fix | Delete
# both have been read successfully.
[1120] Fix | Delete
stdout = None
[1121] Fix | Delete
stderr = None
[1122] Fix | Delete
if self.stdout:
[1123] Fix | Delete
stdout = self._stdout_buff
[1124] Fix | Delete
self.stdout.close()
[1125] Fix | Delete
if self.stderr:
[1126] Fix | Delete
stderr = self._stderr_buff
[1127] Fix | Delete
self.stderr.close()
[1128] Fix | Delete
[1129] Fix | Delete
# All data exchanged. Translate lists into strings.
[1130] Fix | Delete
if stdout is not None:
[1131] Fix | Delete
stdout = stdout[0]
[1132] Fix | Delete
if stderr is not None:
[1133] Fix | Delete
stderr = stderr[0]
[1134] Fix | Delete
[1135] Fix | Delete
return (stdout, stderr)
[1136] Fix | Delete
[1137] Fix | Delete
def send_signal(self, sig):
[1138] Fix | Delete
"""Send a signal to the process."""
[1139] Fix | Delete
# Don't signal a process that we know has already died.
[1140] Fix | Delete
if self.returncode is not None:
[1141] Fix | Delete
return
[1142] Fix | Delete
if sig == signal.SIGTERM:
[1143] Fix | Delete
self.terminate()
[1144] Fix | Delete
elif sig == signal.CTRL_C_EVENT:
[1145] Fix | Delete
os.kill(self.pid, signal.CTRL_C_EVENT)
[1146] Fix | Delete
elif sig == signal.CTRL_BREAK_EVENT:
[1147] Fix | Delete
os.kill(self.pid, signal.CTRL_BREAK_EVENT)
[1148] Fix | Delete
else:
[1149] Fix | Delete
raise ValueError("Unsupported signal: {}".format(sig))
[1150] Fix | Delete
[1151] Fix | Delete
def terminate(self):
[1152] Fix | Delete
"""Terminates the process."""
[1153] Fix | Delete
# Don't terminate a process that we know has already died.
[1154] Fix | Delete
if self.returncode is not None:
[1155] Fix | Delete
return
[1156] Fix | Delete
try:
[1157] Fix | Delete
_winapi.TerminateProcess(self._handle, 1)
[1158] Fix | Delete
except PermissionError:
[1159] Fix | Delete
# ERROR_ACCESS_DENIED (winerror 5) is received when the
[1160] Fix | Delete
# process already died.
[1161] Fix | Delete
rc = _winapi.GetExitCodeProcess(self._handle)
[1162] Fix | Delete
if rc == _winapi.STILL_ACTIVE:
[1163] Fix | Delete
raise
[1164] Fix | Delete
self.returncode = rc
[1165] Fix | Delete
[1166] Fix | Delete
kill = terminate
[1167] Fix | Delete
[1168] Fix | Delete
else:
[1169] Fix | Delete
#
[1170] Fix | Delete
# POSIX methods
[1171] Fix | Delete
#
[1172] Fix | Delete
def _get_handles(self, stdin, stdout, stderr):
[1173] Fix | Delete
"""Construct and return tuple with IO objects:
[1174] Fix | Delete
p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
[1175] Fix | Delete
"""
[1176] Fix | Delete
p2cread, p2cwrite = -1, -1
[1177] Fix | Delete
c2pread, c2pwrite = -1, -1
[1178] Fix | Delete
errread, errwrite = -1, -1
[1179] Fix | Delete
[1180] Fix | Delete
if stdin is None:
[1181] Fix | Delete
pass
[1182] Fix | Delete
elif stdin == PIPE:
[1183] Fix | Delete
p2cread, p2cwrite = os.pipe()
[1184] Fix | Delete
elif stdin == DEVNULL:
[1185] Fix | Delete
p2cread = self._get_devnull()
[1186] Fix | Delete
elif isinstance(stdin, int):
[1187] Fix | Delete
p2cread = stdin
[1188] Fix | Delete
else:
[1189] Fix | Delete
# Assuming file-like object
[1190] Fix | Delete
p2cread = stdin.fileno()
[1191] Fix | Delete
[1192] Fix | Delete
if stdout is None:
[1193] Fix | Delete
pass
[1194] Fix | Delete
elif stdout == PIPE:
[1195] Fix | Delete
c2pread, c2pwrite = os.pipe()
[1196] Fix | Delete
elif stdout == DEVNULL:
[1197] Fix | Delete
c2pwrite = self._get_devnull()
[1198] Fix | Delete
elif isinstance(stdout, int):
[1199] Fix | Delete
c2pwrite = stdout
[1200] Fix | Delete
else:
[1201] Fix | Delete
# Assuming file-like object
[1202] Fix | Delete
c2pwrite = stdout.fileno()
[1203] Fix | Delete
[1204] Fix | Delete
if stderr is None:
[1205] Fix | Delete
pass
[1206] Fix | Delete
elif stderr == PIPE:
[1207] Fix | Delete
errread, errwrite = os.pipe()
[1208] Fix | Delete
elif stderr == STDOUT:
[1209] Fix | Delete
if c2pwrite != -1:
[1210] Fix | Delete
errwrite = c2pwrite
[1211] Fix | Delete
else: # child's stdout is not set, use parent's stdout
[1212] Fix | Delete
errwrite = sys.__stdout__.fileno()
[1213] Fix | Delete
elif stderr == DEVNULL:
[1214] Fix | Delete
errwrite = self._get_devnull()
[1215] Fix | Delete
elif isinstance(stderr, int):
[1216] Fix | Delete
errwrite = stderr
[1217] Fix | Delete
else:
[1218] Fix | Delete
# Assuming file-like object
[1219] Fix | Delete
errwrite = stderr.fileno()
[1220] Fix | Delete
[1221] Fix | Delete
return (p2cread, p2cwrite,
[1222] Fix | Delete
c2pread, c2pwrite,
[1223] Fix | Delete
errread, errwrite)
[1224] Fix | Delete
[1225] Fix | Delete
[1226] Fix | Delete
def _execute_child(self, args, executable, preexec_fn, close_fds,
[1227] Fix | Delete
pass_fds, cwd, env,
[1228] Fix | Delete
startupinfo, creationflags, shell,
[1229] Fix | Delete
p2cread, p2cwrite,
[1230] Fix | Delete
c2pread, c2pwrite,
[1231] Fix | Delete
errread, errwrite,
[1232] Fix | Delete
restore_signals, start_new_session):
[1233] Fix | Delete
"""Execute program (POSIX version)"""
[1234] Fix | Delete
[1235] Fix | Delete
if isinstance(args, (str, bytes)):
[1236] Fix | Delete
args = [args]
[1237] Fix | Delete
else:
[1238] Fix | Delete
args = list(args)
[1239] Fix | Delete
[1240] Fix | Delete
if shell:
[1241] Fix | Delete
args = ["/bin/sh", "-c"] + args
[1242] Fix | Delete
if executable:
[1243] Fix | Delete
args[0] = executable
[1244] Fix | Delete
[1245] Fix | Delete
if executable is None:
[1246] Fix | Delete
executable = args[0]
[1247] Fix | Delete
orig_executable = executable
[1248] Fix | Delete
[1249] Fix | Delete
# For transferring possible exec failure from child to parent.
[1250] Fix | Delete
# Data format: "exception name:hex errno:description"
[1251] Fix | Delete
# Pickle is not used; it is complex and involves memory allocation.
[1252] Fix | Delete
errpipe_read, errpipe_write = os.pipe()
[1253] Fix | Delete
# errpipe_write must not be in the standard io 0, 1, or 2 fd range.
[1254] Fix | Delete
low_fds_to_close = []
[1255] Fix | Delete
while errpipe_write < 3:
[1256] Fix | Delete
low_fds_to_close.append(errpipe_write)
[1257] Fix | Delete
errpipe_write = os.dup(errpipe_write)
[1258] Fix | Delete
for low_fd in low_fds_to_close:
[1259] Fix | Delete
os.close(low_fd)
[1260] Fix | Delete
try:
[1261] Fix | Delete
try:
[1262] Fix | Delete
# We must avoid complex work that could involve
[1263] Fix | Delete
# malloc or free in the child process to avoid
[1264] Fix | Delete
# potential deadlocks, thus we do all this here.
[1265] Fix | Delete
# and pass it to fork_exec()
[1266] Fix | Delete
[1267] Fix | Delete
if env is not None:
[1268] Fix | Delete
env_list = []
[1269] Fix | Delete
for k, v in env.items():
[1270] Fix | Delete
k = os.fsencode(k)
[1271] Fix | Delete
if b'=' in k:
[1272] Fix | Delete
raise ValueError("illegal environment variable name")
[1273] Fix | Delete
env_list.append(k + b'=' + os.fsencode(v))
[1274] Fix | Delete
else:
[1275] Fix | Delete
env_list = None # Use execv instead of execve.
[1276] Fix | Delete
executable = os.fsencode(executable)
[1277] Fix | Delete
if os.path.dirname(executable):
[1278] Fix | Delete
executable_list = (executable,)
[1279] Fix | Delete
else:
[1280] Fix | Delete
# This matches the behavior of os._execvpe().
[1281] Fix | Delete
executable_list = tuple(
[1282] Fix | Delete
os.path.join(os.fsencode(dir), executable)
[1283] Fix | Delete
for dir in os.get_exec_path(env))
[1284] Fix | Delete
fds_to_keep = set(pass_fds)
[1285] Fix | Delete
fds_to_keep.add(errpipe_write)
[1286] Fix | Delete
self.pid = _posixsubprocess.fork_exec(
[1287] Fix | Delete
args, executable_list,
[1288] Fix | Delete
close_fds, tuple(sorted(map(int, fds_to_keep))),
[1289] Fix | Delete
cwd, env_list,
[1290] Fix | Delete
p2cread, p2cwrite, c2pread, c2pwrite,
[1291] Fix | Delete
errread, errwrite,
[1292] Fix | Delete
errpipe_read, errpipe_write,
[1293] Fix | Delete
restore_signals, start_new_session, preexec_fn)
[1294] Fix | Delete
self._child_created = True
[1295] Fix | Delete
finally:
[1296] Fix | Delete
# be sure the FD is closed no matter what
[1297] Fix | Delete
os.close(errpipe_write)
[1298] Fix | Delete
[1299] Fix | Delete
# self._devnull is not always defined.
[1300] Fix | Delete
devnull_fd = getattr(self, '_devnull', None)
[1301] Fix | Delete
if p2cread != -1 and p2cwrite != -1 and p2cread != devnull_fd:
[1302] Fix | Delete
os.close(p2cread)
[1303] Fix | Delete
if c2pwrite != -1 and c2pread != -1 and c2pwrite != devnull_fd:
[1304] Fix | Delete
os.close(c2pwrite)
[1305] Fix | Delete
if errwrite != -1 and errread != -1 and errwrite != devnull_fd:
[1306] Fix | Delete
os.close(errwrite)
[1307] Fix | Delete
if devnull_fd is not None:
[1308] Fix | Delete
os.close(devnull_fd)
[1309] Fix | Delete
# Prevent a double close of these fds from __init__ on error.
[1310] Fix | Delete
self._closed_child_pipe_fds = True
[1311] Fix | Delete
[1312] Fix | Delete
# Wait for exec to fail or succeed; possibly raising an
[1313] Fix | Delete
# exception (limited in size)
[1314] Fix | Delete
errpipe_data = bytearray()
[1315] Fix | Delete
while True:
[1316] Fix | Delete
part = os.read(errpipe_read, 50000)
[1317] Fix | Delete
errpipe_data += part
[1318] Fix | Delete
if not part or len(errpipe_data) > 50000:
[1319] Fix | Delete
break
[1320] Fix | Delete
finally:
[1321] Fix | Delete
# be sure the FD is closed no matter what
[1322] Fix | Delete
os.close(errpipe_read)
[1323] Fix | Delete
[1324] Fix | Delete
if errpipe_data:
[1325] Fix | Delete
try:
[1326] Fix | Delete
pid, sts = os.waitpid(self.pid, 0)
[1327] Fix | Delete
if pid == self.pid:
[1328] Fix | Delete
self._handle_exitstatus(sts)
[1329] Fix | Delete
else:
[1330] Fix | Delete
self.returncode = sys.maxsize
[1331] Fix | Delete
except ChildProcessError:
[1332] Fix | Delete
pass
[1333] Fix | Delete
[1334] Fix | Delete
try:
[1335] Fix | Delete
exception_name, hex_errno, err_msg = (
[1336] Fix | Delete
errpipe_data.split(b':', 2))
[1337] Fix | Delete
# The encoding here should match the encoding
[1338] Fix | Delete
# written in by the subprocess implementations
[1339] Fix | Delete
# like _posixsubprocess
[1340] Fix | Delete
err_msg = err_msg.decode()
[1341] Fix | Delete
except ValueError:
[1342] Fix | Delete
exception_name = b'SubprocessError'
[1343] Fix | Delete
hex_errno = b'0'
[1344] Fix | Delete
err_msg = 'Bad exception data from child: {!r}'.format(
[1345] Fix | Delete
bytes(errpipe_data))
[1346] Fix | Delete
child_exception_type = getattr(
[1347] Fix | Delete
builtins, exception_name.decode('ascii'),
[1348] Fix | Delete
SubprocessError)
[1349] Fix | Delete
if issubclass(child_exception_type, OSError) and hex_errno:
[1350] Fix | Delete
errno_num = int(hex_errno, 16)
[1351] Fix | Delete
child_exec_never_called = (err_msg == "noexec")
[1352] Fix | Delete
if child_exec_never_called:
[1353] Fix | Delete
err_msg = ""
[1354] Fix | Delete
# The error must be from chdir(cwd).
[1355] Fix | Delete
err_filename = cwd
[1356] Fix | Delete
else:
[1357] Fix | Delete
err_filename = orig_executable
[1358] Fix | Delete
if errno_num != 0:
[1359] Fix | Delete
err_msg = os.strerror(errno_num)
[1360] Fix | Delete
if errno_num == errno.ENOENT:
[1361] Fix | Delete
err_msg += ': ' + repr(err_filename)
[1362] Fix | Delete
raise child_exception_type(errno_num, err_msg, err_filename)
[1363] Fix | Delete
raise child_exception_type(err_msg)
[1364] Fix | Delete
[1365] Fix | Delete
[1366] Fix | Delete
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
[1367] Fix | Delete
_WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
[1368] Fix | Delete
_WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
[1369] Fix | Delete
_WSTOPSIG=os.WSTOPSIG):
[1370] Fix | Delete
"""All callers to this function MUST hold self._waitpid_lock."""
[1371] Fix | Delete
# This method is called (indirectly) by __del__, so it cannot
[1372] Fix | Delete
# refer to anything outside of its local scope.
[1373] Fix | Delete
if _WIFSIGNALED(sts):
[1374] Fix | Delete
self.returncode = -_WTERMSIG(sts)
[1375] Fix | Delete
elif _WIFEXITED(sts):
[1376] Fix | Delete
self.returncode = _WEXITSTATUS(sts)
[1377] Fix | Delete
elif _WIFSTOPPED(sts):
[1378] Fix | Delete
self.returncode = -_WSTOPSIG(sts)
[1379] Fix | Delete
else:
[1380] Fix | Delete
# Should never happen
[1381] Fix | Delete
raise SubprocessError("Unknown child exit status!")
[1382] Fix | Delete
[1383] Fix | Delete
[1384] Fix | Delete
def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
[1385] Fix | Delete
_WNOHANG=os.WNOHANG, _ECHILD=errno.ECHILD):
[1386] Fix | Delete
"""Check if child process has terminated. Returns returncode
[1387] Fix | Delete
attribute.
[1388] Fix | Delete
[1389] Fix | Delete
This method is called by __del__, so it cannot reference anything
[1390] Fix | Delete
outside of the local scope (nor can any methods it calls).
[1391] Fix | Delete
[1392] Fix | Delete
"""
[1393] Fix | Delete
if self.returncode is None:
[1394] Fix | Delete
if not self._waitpid_lock.acquire(False):
[1395] Fix | Delete
# Something else is busy calling waitpid. Don't allow two
[1396] Fix | Delete
# at once. We know nothing yet.
[1397] Fix | Delete
return None
[1398] Fix | Delete
try:
[1399] Fix | Delete
if self.returncode is not None:
[1400] Fix | Delete
return self.returncode # Another thread waited.
[1401] Fix | Delete
pid, sts = _waitpid(self.pid, _WNOHANG)
[1402] Fix | Delete
if pid == self.pid:
[1403] Fix | Delete
self._handle_exitstatus(sts)
[1404] Fix | Delete
except OSError as e:
[1405] Fix | Delete
if _deadstate is not None:
[1406] Fix | Delete
self.returncode = _deadstate
[1407] Fix | Delete
elif e.errno == _ECHILD:
[1408] Fix | Delete
# This happens if SIGCLD is set to be ignored or
[1409] Fix | Delete
# waiting for child processes has otherwise been
[1410] Fix | Delete
# disabled for our process. This child is dead, we
[1411] Fix | Delete
# can't get the status.
[1412] Fix | Delete
# http://bugs.python.org/issue15756
[1413] Fix | Delete
self.returncode = 0
[1414] Fix | Delete
finally:
[1415] Fix | Delete
self._waitpid_lock.release()
[1416] Fix | Delete
return self.returncode
[1417] Fix | Delete
[1418] Fix | Delete
[1419] Fix | Delete
def _try_wait(self, wait_flags):
[1420] Fix | Delete
"""All callers to this function MUST hold self._waitpid_lock."""
[1421] Fix | Delete
try:
[1422] Fix | Delete
(pid, sts) = os.waitpid(self.pid, wait_flags)
[1423] Fix | Delete
except ChildProcessError:
[1424] Fix | Delete
# This happens if SIGCLD is set to be ignored or waiting
[1425] Fix | Delete
# for child processes has otherwise been disabled for our
[1426] Fix | Delete
# process. This child is dead, we can't get the status.
[1427] Fix | Delete
pid = self.pid
[1428] Fix | Delete
sts = 0
[1429] Fix | Delete
return (pid, sts)
[1430] Fix | Delete
[1431] Fix | Delete
[1432] Fix | Delete
def wait(self, timeout=None, endtime=None):
[1433] Fix | Delete
"""Wait for child process to terminate. Returns returncode
[1434] Fix | Delete
attribute."""
[1435] Fix | Delete
if self.returncode is not None:
[1436] Fix | Delete
return self.returncode
[1437] Fix | Delete
[1438] Fix | Delete
if endtime is not None:
[1439] Fix | Delete
warnings.warn(
[1440] Fix | Delete
"'endtime' argument is deprecated; use 'timeout'.",
[1441] Fix | Delete
DeprecationWarning,
[1442] Fix | Delete
stacklevel=2)
[1443] Fix | Delete
if endtime is not None or timeout is not None:
[1444] Fix | Delete
if endtime is None:
[1445] Fix | Delete
endtime = _time() + timeout
[1446] Fix | Delete
elif timeout is None:
[1447] Fix | Delete
timeout = self._remaining_time(endtime)
[1448] Fix | Delete
[1449] Fix | Delete
if endtime is not None:
[1450] Fix | Delete
# Enter a busy loop if we have a timeout. This busy loop was
[1451] Fix | Delete
# cribbed from Lib/threading.py in Thread.wait() at r71065.
[1452] Fix | Delete
delay = 0.0005 # 500 us -> initial delay of 1 ms
[1453] Fix | Delete
while True:
[1454] Fix | Delete
if self._waitpid_lock.acquire(False):
[1455] Fix | Delete
try:
[1456] Fix | Delete
if self.returncode is not None:
[1457] Fix | Delete
break # Another thread waited.
[1458] Fix | Delete
(pid, sts) = self._try_wait(os.WNOHANG)
[1459] Fix | Delete
assert pid == self.pid or pid == 0
[1460] Fix | Delete
if pid == self.pid:
[1461] Fix | Delete
self._handle_exitstatus(sts)
[1462] Fix | Delete
break
[1463] Fix | Delete
finally:
[1464] Fix | Delete
self._waitpid_lock.release()
[1465] Fix | Delete
remaining = self._remaining_time(endtime)
[1466] Fix | Delete
if remaining <= 0:
[1467] Fix | Delete
raise TimeoutExpired(self.args, timeout)
[1468] Fix | Delete
delay = min(delay * 2, remaining, .05)
[1469] Fix | Delete
time.sleep(delay)
[1470] Fix | Delete
else:
[1471] Fix | Delete
while self.returncode is None:
[1472] Fix | Delete
with self._waitpid_lock:
[1473] Fix | Delete
if self.returncode is not None:
[1474] Fix | Delete
break # Another thread waited.
[1475] Fix | Delete
(pid, sts) = self._try_wait(0)
[1476] Fix | Delete
# Check the pid and loop as waitpid has been known to
[1477] Fix | Delete
# return 0 even without WNOHANG in odd situations.
[1478] Fix | Delete
# http://bugs.python.org/issue14396.
[1479] Fix | Delete
if pid == self.pid:
[1480] Fix | Delete
self._handle_exitstatus(sts)
[1481] Fix | Delete
return self.returncode
[1482] Fix | Delete
[1483] Fix | Delete
[1484] Fix | Delete
def _communicate(self, input, endtime, orig_timeout):
[1485] Fix | Delete
if self.stdin and not self._communication_started:
[1486] Fix | Delete
# Flush stdio buffer. This might block, if the user has
[1487] Fix | Delete
# been writing to .stdin in an uncontrolled fashion.
[1488] Fix | Delete
try:
[1489] Fix | Delete
self.stdin.flush()
[1490] Fix | Delete
except BrokenPipeError:
[1491] Fix | Delete
pass # communicate() must ignore BrokenPipeError.
[1492] Fix | Delete
if not input:
[1493] Fix | Delete
try:
[1494] Fix | Delete
self.stdin.close()
[1495] Fix | Delete
except BrokenPipeError:
[1496] Fix | Delete
pass # communicate() must ignore BrokenPipeError.
[1497] Fix | Delete
[1498] Fix | Delete
stdout = None
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function