Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/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"""subprocess - 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. This module
[12] Fix | Delete
intends to replace several older modules and functions:
[13] Fix | Delete
[14] Fix | Delete
os.system
[15] Fix | Delete
os.spawn*
[16] Fix | Delete
os.popen*
[17] Fix | Delete
popen2.*
[18] Fix | Delete
commands.*
[19] Fix | Delete
[20] Fix | Delete
Information about how the subprocess module can be used to replace these
[21] Fix | Delete
modules and functions can be found below.
[22] Fix | Delete
[23] Fix | Delete
[24] Fix | Delete
[25] Fix | Delete
Using the subprocess module
[26] Fix | Delete
===========================
[27] Fix | Delete
This module defines one class called Popen:
[28] Fix | Delete
[29] Fix | Delete
class Popen(args, bufsize=0, executable=None,
[30] Fix | Delete
stdin=None, stdout=None, stderr=None,
[31] Fix | Delete
preexec_fn=None, close_fds=False, shell=False,
[32] Fix | Delete
cwd=None, env=None, universal_newlines=False,
[33] Fix | Delete
startupinfo=None, creationflags=0):
[34] Fix | Delete
[35] Fix | Delete
[36] Fix | Delete
Arguments are:
[37] Fix | Delete
[38] Fix | Delete
args should be a string, or a sequence of program arguments. The
[39] Fix | Delete
program to execute is normally the first item in the args sequence or
[40] Fix | Delete
string, but can be explicitly set by using the executable argument.
[41] Fix | Delete
[42] Fix | Delete
On UNIX, with shell=False (default): In this case, the Popen class
[43] Fix | Delete
uses os.execvp() to execute the child program. args should normally
[44] Fix | Delete
be a sequence. A string will be treated as a sequence with the string
[45] Fix | Delete
as the only item (the program to execute).
[46] Fix | Delete
[47] Fix | Delete
On UNIX, with shell=True: If args is a string, it specifies the
[48] Fix | Delete
command string to execute through the shell. If args is a sequence,
[49] Fix | Delete
the first item specifies the command string, and any additional items
[50] Fix | Delete
will be treated as additional shell arguments.
[51] Fix | Delete
[52] Fix | Delete
On Windows: the Popen class uses CreateProcess() to execute the child
[53] Fix | Delete
program, which operates on strings. If args is a sequence, it will be
[54] Fix | Delete
converted to a string using the list2cmdline method. Please note that
[55] Fix | Delete
not all MS Windows applications interpret the command line the same
[56] Fix | Delete
way: The list2cmdline is designed for applications using the same
[57] Fix | Delete
rules as the MS C runtime.
[58] Fix | Delete
[59] Fix | Delete
bufsize, if given, has the same meaning as the corresponding argument
[60] Fix | Delete
to the built-in open() function: 0 means unbuffered, 1 means line
[61] Fix | Delete
buffered, any other positive value means use a buffer of
[62] Fix | Delete
(approximately) that size. A negative bufsize means to use the system
[63] Fix | Delete
default, which usually means fully buffered. The default value for
[64] Fix | Delete
bufsize is 0 (unbuffered).
[65] Fix | Delete
[66] Fix | Delete
stdin, stdout and stderr specify the executed programs' standard
[67] Fix | Delete
input, standard output and standard error file handles, respectively.
[68] Fix | Delete
Valid values are PIPE, an existing file descriptor (a positive
[69] Fix | Delete
integer), an existing file object, and None. PIPE indicates that a
[70] Fix | Delete
new pipe to the child should be created. With None, no redirection
[71] Fix | Delete
will occur; the child's file handles will be inherited from the
[72] Fix | Delete
parent. Additionally, stderr can be STDOUT, which indicates that the
[73] Fix | Delete
stderr data from the applications should be captured into the same
[74] Fix | Delete
file handle as for stdout.
[75] Fix | Delete
[76] Fix | Delete
If preexec_fn is set to a callable object, this object will be called
[77] Fix | Delete
in the child process just before the child is executed.
[78] Fix | Delete
[79] Fix | Delete
If close_fds is true, all file descriptors except 0, 1 and 2 will be
[80] Fix | Delete
closed before the child process is executed.
[81] Fix | Delete
[82] Fix | Delete
if shell is true, the specified command will be executed through the
[83] Fix | Delete
shell.
[84] Fix | Delete
[85] Fix | Delete
If cwd is not None, the current directory will be changed to cwd
[86] Fix | Delete
before the child is executed.
[87] Fix | Delete
[88] Fix | Delete
If env is not None, it defines the environment variables for the new
[89] Fix | Delete
process.
[90] Fix | Delete
[91] Fix | Delete
If universal_newlines is true, the file objects stdout and stderr are
[92] Fix | Delete
opened as a text files, but lines may be terminated by any of '\n',
[93] Fix | Delete
the Unix end-of-line convention, '\r', the Macintosh convention or
[94] Fix | Delete
'\r\n', the Windows convention. All of these external representations
[95] Fix | Delete
are seen as '\n' by the Python program. Note: This feature is only
[96] Fix | Delete
available if Python is built with universal newline support (the
[97] Fix | Delete
default). Also, the newlines attribute of the file objects stdout,
[98] Fix | Delete
stdin and stderr are not updated by the communicate() method.
[99] Fix | Delete
[100] Fix | Delete
The startupinfo and creationflags, if given, will be passed to the
[101] Fix | Delete
underlying CreateProcess() function. They can specify things such as
[102] Fix | Delete
appearance of the main window and priority for the new process.
[103] Fix | Delete
(Windows only)
[104] Fix | Delete
[105] Fix | Delete
[106] Fix | Delete
This module also defines some shortcut functions:
[107] Fix | Delete
[108] Fix | Delete
call(*popenargs, **kwargs):
[109] Fix | Delete
Run command with arguments. Wait for command to complete, then
[110] Fix | Delete
return the returncode attribute.
[111] Fix | Delete
[112] Fix | Delete
The arguments are the same as for the Popen constructor. Example:
[113] Fix | Delete
[114] Fix | Delete
retcode = call(["ls", "-l"])
[115] Fix | Delete
[116] Fix | Delete
check_call(*popenargs, **kwargs):
[117] Fix | Delete
Run command with arguments. Wait for command to complete. If the
[118] Fix | Delete
exit code was zero then return, otherwise raise
[119] Fix | Delete
CalledProcessError. The CalledProcessError object will have the
[120] Fix | Delete
return code in the returncode attribute.
[121] Fix | Delete
[122] Fix | Delete
The arguments are the same as for the Popen constructor. Example:
[123] Fix | Delete
[124] Fix | Delete
check_call(["ls", "-l"])
[125] Fix | Delete
[126] Fix | Delete
check_output(*popenargs, **kwargs):
[127] Fix | Delete
Run command with arguments and return its output as a byte string.
[128] Fix | Delete
[129] Fix | Delete
If the exit code was non-zero it raises a CalledProcessError. The
[130] Fix | Delete
CalledProcessError object will have the return code in the returncode
[131] Fix | Delete
attribute and output in the output attribute.
[132] Fix | Delete
[133] Fix | Delete
The arguments are the same as for the Popen constructor. Example:
[134] Fix | Delete
[135] Fix | Delete
output = check_output(["ls", "-l", "/dev/null"])
[136] Fix | Delete
[137] Fix | Delete
[138] Fix | Delete
Exceptions
[139] Fix | Delete
----------
[140] Fix | Delete
Exceptions raised in the child process, before the new program has
[141] Fix | Delete
started to execute, will be re-raised in the parent. Additionally,
[142] Fix | Delete
the exception object will have one extra attribute called
[143] Fix | Delete
'child_traceback', which is a string containing traceback information
[144] Fix | Delete
from the child's point of view.
[145] Fix | Delete
[146] Fix | Delete
The most common exception raised is OSError. This occurs, for
[147] Fix | Delete
example, when trying to execute a non-existent file. Applications
[148] Fix | Delete
should prepare for OSErrors.
[149] Fix | Delete
[150] Fix | Delete
A ValueError will be raised if Popen is called with invalid arguments.
[151] Fix | Delete
[152] Fix | Delete
check_call() and check_output() will raise CalledProcessError, if the
[153] Fix | Delete
called process returns a non-zero return code.
[154] Fix | Delete
[155] Fix | Delete
[156] Fix | Delete
Security
[157] Fix | Delete
--------
[158] Fix | Delete
Unlike some other popen functions, this implementation will never call
[159] Fix | Delete
/bin/sh implicitly. This means that all characters, including shell
[160] Fix | Delete
metacharacters, can safely be passed to child processes.
[161] Fix | Delete
[162] Fix | Delete
[163] Fix | Delete
Popen objects
[164] Fix | Delete
=============
[165] Fix | Delete
Instances of the Popen class have the following methods:
[166] Fix | Delete
[167] Fix | Delete
poll()
[168] Fix | Delete
Check if child process has terminated. Returns returncode
[169] Fix | Delete
attribute.
[170] Fix | Delete
[171] Fix | Delete
wait()
[172] Fix | Delete
Wait for child process to terminate. Returns returncode attribute.
[173] Fix | Delete
[174] Fix | Delete
communicate(input=None)
[175] Fix | Delete
Interact with process: Send data to stdin. Read data from stdout
[176] Fix | Delete
and stderr, until end-of-file is reached. Wait for process to
[177] Fix | Delete
terminate. The optional input argument should be a string to be
[178] Fix | Delete
sent to the child process, or None, if no data should be sent to
[179] Fix | Delete
the child.
[180] Fix | Delete
[181] Fix | Delete
communicate() returns a tuple (stdout, stderr).
[182] Fix | Delete
[183] Fix | Delete
Note: The data read is buffered in memory, so do not use this
[184] Fix | Delete
method if the data size is large or unlimited.
[185] Fix | Delete
[186] Fix | Delete
The following attributes are also available:
[187] Fix | Delete
[188] Fix | Delete
stdin
[189] Fix | Delete
If the stdin argument is PIPE, this attribute is a file object
[190] Fix | Delete
that provides input to the child process. Otherwise, it is None.
[191] Fix | Delete
[192] Fix | Delete
stdout
[193] Fix | Delete
If the stdout argument is PIPE, this attribute is a file object
[194] Fix | Delete
that provides output from the child process. Otherwise, it is
[195] Fix | Delete
None.
[196] Fix | Delete
[197] Fix | Delete
stderr
[198] Fix | Delete
If the stderr argument is PIPE, this attribute is file object that
[199] Fix | Delete
provides error output from the child process. Otherwise, it is
[200] Fix | Delete
None.
[201] Fix | Delete
[202] Fix | Delete
pid
[203] Fix | Delete
The process ID of the child process.
[204] Fix | Delete
[205] Fix | Delete
returncode
[206] Fix | Delete
The child return code. A None value indicates that the process
[207] Fix | Delete
hasn't terminated yet. A negative value -N indicates that the
[208] Fix | Delete
child was terminated by signal N (UNIX only).
[209] Fix | Delete
[210] Fix | Delete
[211] Fix | Delete
Replacing older functions with the subprocess module
[212] Fix | Delete
====================================================
[213] Fix | Delete
In this section, "a ==> b" means that b can be used as a replacement
[214] Fix | Delete
for a.
[215] Fix | Delete
[216] Fix | Delete
Note: All functions in this section fail (more or less) silently if
[217] Fix | Delete
the executed program cannot be found; this module raises an OSError
[218] Fix | Delete
exception.
[219] Fix | Delete
[220] Fix | Delete
In the following examples, we assume that the subprocess module is
[221] Fix | Delete
imported with "from subprocess import *".
[222] Fix | Delete
[223] Fix | Delete
[224] Fix | Delete
Replacing /bin/sh shell backquote
[225] Fix | Delete
---------------------------------
[226] Fix | Delete
output=`mycmd myarg`
[227] Fix | Delete
==>
[228] Fix | Delete
output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]
[229] Fix | Delete
[230] Fix | Delete
[231] Fix | Delete
Replacing shell pipe line
[232] Fix | Delete
-------------------------
[233] Fix | Delete
output=`dmesg | grep hda`
[234] Fix | Delete
==>
[235] Fix | Delete
p1 = Popen(["dmesg"], stdout=PIPE)
[236] Fix | Delete
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
[237] Fix | Delete
output = p2.communicate()[0]
[238] Fix | Delete
[239] Fix | Delete
[240] Fix | Delete
Replacing os.system()
[241] Fix | Delete
---------------------
[242] Fix | Delete
sts = os.system("mycmd" + " myarg")
[243] Fix | Delete
==>
[244] Fix | Delete
p = Popen("mycmd" + " myarg", shell=True)
[245] Fix | Delete
pid, sts = os.waitpid(p.pid, 0)
[246] Fix | Delete
[247] Fix | Delete
Note:
[248] Fix | Delete
[249] Fix | Delete
* Calling the program through the shell is usually not required.
[250] Fix | Delete
[251] Fix | Delete
* It's easier to look at the returncode attribute than the
[252] Fix | Delete
exitstatus.
[253] Fix | Delete
[254] Fix | Delete
A more real-world example would look like this:
[255] Fix | Delete
[256] Fix | Delete
try:
[257] Fix | Delete
retcode = call("mycmd" + " myarg", shell=True)
[258] Fix | Delete
if retcode < 0:
[259] Fix | Delete
print >>sys.stderr, "Child was terminated by signal", -retcode
[260] Fix | Delete
else:
[261] Fix | Delete
print >>sys.stderr, "Child returned", retcode
[262] Fix | Delete
except OSError, e:
[263] Fix | Delete
print >>sys.stderr, "Execution failed:", e
[264] Fix | Delete
[265] Fix | Delete
[266] Fix | Delete
Replacing os.spawn*
[267] Fix | Delete
-------------------
[268] Fix | Delete
P_NOWAIT example:
[269] Fix | Delete
[270] Fix | Delete
pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg")
[271] Fix | Delete
==>
[272] Fix | Delete
pid = Popen(["/bin/mycmd", "myarg"]).pid
[273] Fix | Delete
[274] Fix | Delete
[275] Fix | Delete
P_WAIT example:
[276] Fix | Delete
[277] Fix | Delete
retcode = os.spawnlp(os.P_WAIT, "/bin/mycmd", "mycmd", "myarg")
[278] Fix | Delete
==>
[279] Fix | Delete
retcode = call(["/bin/mycmd", "myarg"])
[280] Fix | Delete
[281] Fix | Delete
[282] Fix | Delete
Vector example:
[283] Fix | Delete
[284] Fix | Delete
os.spawnvp(os.P_NOWAIT, path, args)
[285] Fix | Delete
==>
[286] Fix | Delete
Popen([path] + args[1:])
[287] Fix | Delete
[288] Fix | Delete
[289] Fix | Delete
Environment example:
[290] Fix | Delete
[291] Fix | Delete
os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env)
[292] Fix | Delete
==>
[293] Fix | Delete
Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
[294] Fix | Delete
[295] Fix | Delete
[296] Fix | Delete
Replacing os.popen*
[297] Fix | Delete
-------------------
[298] Fix | Delete
pipe = os.popen("cmd", mode='r', bufsize)
[299] Fix | Delete
==>
[300] Fix | Delete
pipe = Popen("cmd", shell=True, bufsize=bufsize, stdout=PIPE).stdout
[301] Fix | Delete
[302] Fix | Delete
pipe = os.popen("cmd", mode='w', bufsize)
[303] Fix | Delete
==>
[304] Fix | Delete
pipe = Popen("cmd", shell=True, bufsize=bufsize, stdin=PIPE).stdin
[305] Fix | Delete
[306] Fix | Delete
[307] Fix | Delete
(child_stdin, child_stdout) = os.popen2("cmd", mode, bufsize)
[308] Fix | Delete
==>
[309] Fix | Delete
p = Popen("cmd", shell=True, bufsize=bufsize,
[310] Fix | Delete
stdin=PIPE, stdout=PIPE, close_fds=True)
[311] Fix | Delete
(child_stdin, child_stdout) = (p.stdin, p.stdout)
[312] Fix | Delete
[313] Fix | Delete
[314] Fix | Delete
(child_stdin,
[315] Fix | Delete
child_stdout,
[316] Fix | Delete
child_stderr) = os.popen3("cmd", mode, bufsize)
[317] Fix | Delete
==>
[318] Fix | Delete
p = Popen("cmd", shell=True, bufsize=bufsize,
[319] Fix | Delete
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
[320] Fix | Delete
(child_stdin,
[321] Fix | Delete
child_stdout,
[322] Fix | Delete
child_stderr) = (p.stdin, p.stdout, p.stderr)
[323] Fix | Delete
[324] Fix | Delete
[325] Fix | Delete
(child_stdin, child_stdout_and_stderr) = os.popen4("cmd", mode,
[326] Fix | Delete
bufsize)
[327] Fix | Delete
==>
[328] Fix | Delete
p = Popen("cmd", shell=True, bufsize=bufsize,
[329] Fix | Delete
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
[330] Fix | Delete
(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
[331] Fix | Delete
[332] Fix | Delete
On Unix, os.popen2, os.popen3 and os.popen4 also accept a sequence as
[333] Fix | Delete
the command to execute, in which case arguments will be passed
[334] Fix | Delete
directly to the program without shell intervention. This usage can be
[335] Fix | Delete
replaced as follows:
[336] Fix | Delete
[337] Fix | Delete
(child_stdin, child_stdout) = os.popen2(["/bin/ls", "-l"], mode,
[338] Fix | Delete
bufsize)
[339] Fix | Delete
==>
[340] Fix | Delete
p = Popen(["/bin/ls", "-l"], bufsize=bufsize, stdin=PIPE, stdout=PIPE)
[341] Fix | Delete
(child_stdin, child_stdout) = (p.stdin, p.stdout)
[342] Fix | Delete
[343] Fix | Delete
Return code handling translates as follows:
[344] Fix | Delete
[345] Fix | Delete
pipe = os.popen("cmd", 'w')
[346] Fix | Delete
...
[347] Fix | Delete
rc = pipe.close()
[348] Fix | Delete
if rc is not None and rc % 256:
[349] Fix | Delete
print "There were some errors"
[350] Fix | Delete
==>
[351] Fix | Delete
process = Popen("cmd", 'w', shell=True, stdin=PIPE)
[352] Fix | Delete
...
[353] Fix | Delete
process.stdin.close()
[354] Fix | Delete
if process.wait() != 0:
[355] Fix | Delete
print "There were some errors"
[356] Fix | Delete
[357] Fix | Delete
[358] Fix | Delete
Replacing popen2.*
[359] Fix | Delete
------------------
[360] Fix | Delete
(child_stdout, child_stdin) = popen2.popen2("somestring", bufsize, mode)
[361] Fix | Delete
==>
[362] Fix | Delete
p = Popen(["somestring"], shell=True, bufsize=bufsize
[363] Fix | Delete
stdin=PIPE, stdout=PIPE, close_fds=True)
[364] Fix | Delete
(child_stdout, child_stdin) = (p.stdout, p.stdin)
[365] Fix | Delete
[366] Fix | Delete
On Unix, popen2 also accepts a sequence as the command to execute, in
[367] Fix | Delete
which case arguments will be passed directly to the program without
[368] Fix | Delete
shell intervention. This usage can be replaced as follows:
[369] Fix | Delete
[370] Fix | Delete
(child_stdout, child_stdin) = popen2.popen2(["mycmd", "myarg"], bufsize,
[371] Fix | Delete
mode)
[372] Fix | Delete
==>
[373] Fix | Delete
p = Popen(["mycmd", "myarg"], bufsize=bufsize,
[374] Fix | Delete
stdin=PIPE, stdout=PIPE, close_fds=True)
[375] Fix | Delete
(child_stdout, child_stdin) = (p.stdout, p.stdin)
[376] Fix | Delete
[377] Fix | Delete
The popen2.Popen3 and popen2.Popen4 basically works as subprocess.Popen,
[378] Fix | Delete
except that:
[379] Fix | Delete
[380] Fix | Delete
* subprocess.Popen raises an exception if the execution fails
[381] Fix | Delete
* the capturestderr argument is replaced with the stderr argument.
[382] Fix | Delete
* stdin=PIPE and stdout=PIPE must be specified.
[383] Fix | Delete
* popen2 closes all filedescriptors by default, but you have to specify
[384] Fix | Delete
close_fds=True with subprocess.Popen.
[385] Fix | Delete
"""
[386] Fix | Delete
[387] Fix | Delete
import sys
[388] Fix | Delete
mswindows = (sys.platform == "win32")
[389] Fix | Delete
[390] Fix | Delete
import os
[391] Fix | Delete
import types
[392] Fix | Delete
import traceback
[393] Fix | Delete
import gc
[394] Fix | Delete
import signal
[395] Fix | Delete
import errno
[396] Fix | Delete
[397] Fix | Delete
# Exception classes used by this module.
[398] Fix | Delete
class CalledProcessError(Exception):
[399] Fix | Delete
"""This exception is raised when a process run by check_call() or
[400] Fix | Delete
check_output() returns a non-zero exit status.
[401] Fix | Delete
The exit status will be stored in the returncode attribute;
[402] Fix | Delete
check_output() will also store the output in the output attribute.
[403] Fix | Delete
"""
[404] Fix | Delete
def __init__(self, returncode, cmd, output=None):
[405] Fix | Delete
self.returncode = returncode
[406] Fix | Delete
self.cmd = cmd
[407] Fix | Delete
self.output = output
[408] Fix | Delete
def __str__(self):
[409] Fix | Delete
return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
[410] Fix | Delete
[411] Fix | Delete
[412] Fix | Delete
if mswindows:
[413] Fix | Delete
import threading
[414] Fix | Delete
import msvcrt
[415] Fix | Delete
import _subprocess
[416] Fix | Delete
class STARTUPINFO:
[417] Fix | Delete
dwFlags = 0
[418] Fix | Delete
hStdInput = None
[419] Fix | Delete
hStdOutput = None
[420] Fix | Delete
hStdError = None
[421] Fix | Delete
wShowWindow = 0
[422] Fix | Delete
class pywintypes:
[423] Fix | Delete
error = IOError
[424] Fix | Delete
else:
[425] Fix | Delete
import select
[426] Fix | Delete
_has_poll = hasattr(select, 'poll')
[427] Fix | Delete
import fcntl
[428] Fix | Delete
import pickle
[429] Fix | Delete
[430] Fix | Delete
# When select or poll has indicated that the file is writable,
[431] Fix | Delete
# we can write up to _PIPE_BUF bytes without risk of blocking.
[432] Fix | Delete
# POSIX defines PIPE_BUF as >= 512.
[433] Fix | Delete
_PIPE_BUF = getattr(select, 'PIPE_BUF', 512)
[434] Fix | Delete
[435] Fix | Delete
[436] Fix | Delete
__all__ = ["Popen", "PIPE", "STDOUT", "call", "check_call",
[437] Fix | Delete
"check_output", "CalledProcessError"]
[438] Fix | Delete
[439] Fix | Delete
if mswindows:
[440] Fix | Delete
from _subprocess import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
[441] Fix | Delete
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
[442] Fix | Delete
STD_ERROR_HANDLE, SW_HIDE,
[443] Fix | Delete
STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW)
[444] Fix | Delete
[445] Fix | Delete
__all__.extend(["CREATE_NEW_CONSOLE", "CREATE_NEW_PROCESS_GROUP",
[446] Fix | Delete
"STD_INPUT_HANDLE", "STD_OUTPUT_HANDLE",
[447] Fix | Delete
"STD_ERROR_HANDLE", "SW_HIDE",
[448] Fix | Delete
"STARTF_USESTDHANDLES", "STARTF_USESHOWWINDOW"])
[449] Fix | Delete
try:
[450] Fix | Delete
MAXFD = os.sysconf("SC_OPEN_MAX")
[451] Fix | Delete
except:
[452] Fix | Delete
MAXFD = 256
[453] Fix | Delete
[454] Fix | Delete
_active = []
[455] Fix | Delete
[456] Fix | Delete
def _cleanup():
[457] Fix | Delete
for inst in _active[:]:
[458] Fix | Delete
res = inst._internal_poll(_deadstate=sys.maxint)
[459] Fix | Delete
if res is not None:
[460] Fix | Delete
try:
[461] Fix | Delete
_active.remove(inst)
[462] Fix | Delete
except ValueError:
[463] Fix | Delete
# This can happen if two threads create a new Popen instance.
[464] Fix | Delete
# It's harmless that it was already removed, so ignore.
[465] Fix | Delete
pass
[466] Fix | Delete
[467] Fix | Delete
PIPE = -1
[468] Fix | Delete
STDOUT = -2
[469] Fix | Delete
[470] Fix | Delete
[471] Fix | Delete
def _eintr_retry_call(func, *args):
[472] Fix | Delete
while True:
[473] Fix | Delete
try:
[474] Fix | Delete
return func(*args)
[475] Fix | Delete
except (OSError, IOError) as e:
[476] Fix | Delete
if e.errno == errno.EINTR:
[477] Fix | Delete
continue
[478] Fix | Delete
raise
[479] Fix | Delete
[480] Fix | Delete
[481] Fix | Delete
# XXX This function is only used by multiprocessing and the test suite,
[482] Fix | Delete
# but it's here so that it can be imported when Python is compiled without
[483] Fix | Delete
# threads.
[484] Fix | Delete
[485] Fix | Delete
def _args_from_interpreter_flags():
[486] Fix | Delete
"""Return a list of command-line arguments reproducing the current
[487] Fix | Delete
settings in sys.flags and sys.warnoptions."""
[488] Fix | Delete
flag_opt_map = {
[489] Fix | Delete
'debug': 'd',
[490] Fix | Delete
# 'inspect': 'i',
[491] Fix | Delete
# 'interactive': 'i',
[492] Fix | Delete
'optimize': 'O',
[493] Fix | Delete
'dont_write_bytecode': 'B',
[494] Fix | Delete
'no_user_site': 's',
[495] Fix | Delete
'no_site': 'S',
[496] Fix | Delete
'ignore_environment': 'E',
[497] Fix | Delete
'verbose': 'v',
[498] Fix | Delete
'bytes_warning': 'b',
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function