本文整理汇总了Python中subprocess.Popen.returncode方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.returncode方法的具体用法?Python Popen.returncode怎么用?Python Popen.returncode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess.Popen
的用法示例。
在下文中一共展示了Popen.returncode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lets_run_a_test
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import returncode [as 别名]
def lets_run_a_test(name):
sitl_args = [
"dronekit-sitl",
"copter-3.3-rc5",
"-I0",
"-S",
"--model",
"quad",
"--home=-35.363261,149.165230,584,353",
]
speedup = os.environ.get("TEST_SPEEDUP", "1")
rate = os.environ.get("TEST_RATE", "200")
sitl_args += ["--speedup", str(speedup), "-r", str(rate)]
# Change CPU core affinity.
# TODO change affinity on osx/linux
if sys.platform == "win32":
# 0x14 = 0b1110 = all cores except cpu 1
sitl = Popen(
["start", "/affinity", "14", "/realtime", "/b", "/wait"] + sitl_args, shell=True, stdout=PIPE, stderr=PIPE
)
else:
sitl = Popen(sitl_args, stdout=PIPE, stderr=PIPE)
bg.append(sitl)
while sitl.poll() == None:
line = sitl.stdout.readline()
if "Waiting for connection" in line:
break
if sitl.poll() != None and sitl.returncode != 0:
print("[runner] ...aborting with SITL error code " + str(sitl.returncode))
sys.stdout.flush()
sys.stderr.flush()
sys.exit(sitl.returncode)
newenv = os.environ.copy()
newenv["PYTHONUNBUFFERED"] = "1"
if sys.platform == "win32":
out_fd = 1
err_fd = 2
else:
out_fd = os.dup(1)
err_fd = os.dup(2)
(out_fd, out_h) = wrap_fd(out_fd)
(err_fd, err_h) = wrap_fd(err_fd)
newenv["TEST_WRITE_OUT"] = out_fd
newenv["TEST_WRITE_ERR"] = err_fd
newenv["TEST_NAME"] = name
print("[runner] " + name, file=sys.stderr)
sys.stdout.flush()
sys.stderr.flush()
mavproxy_verbose = os.environ.get("TEST_VERBOSE", "0") != "0"
timeout = 5 * 60
try:
if sys.platform == "win32":
try:
# Try to find installed Python MAVProxy module.
import imp
imp.find_module("MAVProxy")
mavprog = [sys.executable, "-m", "MAVProxy.mavproxy"]
except:
# Uses mavproxy.exe instead.
mavprog = ["mavproxy"]
else:
mavprog = [sys.executable, "-m", "MAVProxy.mavproxy"]
p = Popen(
mavprog + ["--logfile=" + tempfile.mkstemp()[1], "--master=tcp:127.0.0.1:5760"],
cwd=testpath,
env=newenv,
stdin=PIPE,
stdout=PIPE,
stderr=PIPE if not mavproxy_verbose else None,
)
bg.append(p)
# TODO this sleep is only for us to waiting until
# all parameters to be received; would prefer to
# move this to testlib.py and happen asap
while p.poll() == None:
line = p.stdout.readline()
if mavproxy_verbose:
sys.stdout.write(line)
sys.stdout.flush()
if "parameters" in line:
break
time.sleep(3)
# NOTE these are *very inappropriate settings*
# to make on a real vehicle. They are leveraged
# exclusively for simulation. Take heed!!!
p.stdin.write("param set ARMING_CHECK 0\n")
#.........这里部分代码省略.........
示例2: calculateKaKs
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import returncode [as 别名]
def calculateKaKs(indir, outdir, method, axt):
'''Calculates substition rates.'''
with open(axt, "r") as infile:
filename = axt.split("/")[-1]
# Create output file
outfile = (outdir + filename.split(".")[0] + ".kaks")
cmd = "bin/KaKs_Calculator -i "+axt+" -o "+outfile+" -m "+method
ck = Popen(split(cmd), stdout = DEVNULL)
ck.wait()
if ck.returncode() == 0:
return True
示例3: run_cmd
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import returncode [as 别名]
def run_cmd(cmd, my_cwd=None):
'''
Description:
Run a command given by a dictionary, check for stderr output,
return code.
To check the return code catch SystemExit then examine:
ret['subproc'].returncode.
Input:
cmd - a list containing the command to execute.
e.g.: cmd = ['ls', '/tmp']
Returns:
ret - a dictionary upon return contains the keys:
'subproc', 'err', 'out'
ret['subproc'].returncode = subprocess return code
ret['err'] = command errors string.
ret['out'] = command out list.
Example:
cmd = ['ls', '/tmp']
ret = run_cmd(cmd)
ret.keys()
['subproc', 'err', 'out']
ret['subproc'].returncode
0
ret['err']
''
ret['out']
'''
pfail = SubprocReturn()
# Return dictionary to contain keys: 'cmd', 'subproc', 'err', 'out'
ret = {'subproc': None, 'err': '', 'out': ''}
try:
ret['subproc'] = Popen(cmd, cwd=my_cwd, stdout=PIPE, stderr=PIPE)
# unable to find command will result in an OSError
except OSError, err:
if not ret['subproc']:
ret['subproc'] = pfail
ret['subproc'].returncode = 127 # command not found
ret['err'] = str(err)
return ret
示例4: exec_shell_command
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import returncode [as 别名]
def exec_shell_command(arguments, env=None):
if env is None:
env = {}
merge_env = environ.copy()
merge_env.update(env)
p = Popen(arguments, env=merge_env)
try:
p.wait()
except KeyboardInterrupt:
p.kill()
p.wait()
p.returncode = 1
return p.returncode
示例5: execute_anybodycon
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import returncode [as 别名]
#.........这里部分代码省略.........
(Defaults to False)
env: dict
Environment varaibles which are passed to the started AnyBody console
application.
priority : int, optional
The priority of the subprocesses. This can be on of the following:
``anypytools.IDLE_PRIORITY_CLASS``, ``anypytools.BELOW_NORMAL_PRIORITY_CLASS``,
``anypytools.NORMAL_PRIORITY_CLASS``, ``anypytools.HIGH_PRIORITY_CLASS``
Default is BELOW_NORMAL_PRIORITY_CLASS.
debug_mode : int
The AMS debug mode to use. Defaults to 0 which is disabled. 1 correspond to
crashdump enabled
Returns
-------
int
The return code from the AnyBody Console application.
"""
if logfile is None:
logfile = sys.stdout
try:
macro_filename = os.path.splitext(logfile.name)[0] + ".anymcr"
except AttributeError:
macro_filename = "macrofile.anymcr"
if anybodycon_path is None:
anybodycon_path = get_anybodycon_path()
if macro and macro[-1] != "exit":
macro.append("exit")
if not os.path.isfile(anybodycon_path):
raise IOError("Can not find anybodycon.exe: " + anybodycon_path)
with open(macro_filename, "w+b") as macro_file:
macro_file.write("\n".join(macro).encode("UTF-8"))
macro_file.flush()
anybodycmd = [
os.path.realpath(anybodycon_path),
"--macro=",
macro_file.name,
"/ni",
"/deb",
str(debug_mode),
]
if sys.platform.startswith("win"):
# Don't display the Windows GPF dialog if the invoked program dies.
# See comp.os.ms-windows.programmer.win32
# How to suppress crash notification dialog?, Jan 14,2004 -
# Raymond Chen's response [1]
SEM_NOGPFAULTERRORBOX = 0x0002 # From MSDN
ctypes.windll.kernel32.SetErrorMode(SEM_NOGPFAULTERRORBOX)
subprocess_flags = 0x8000000 # win32con.CREATE_NO_WINDOW?
else:
subprocess_flags = 0
subprocess_flags |= priority
# Check global module flag to avoid starting processes after
# the user cancelled the processes
timeout_time = time.process_time() + timeout
proc = Popen(
anybodycmd,
stdout=logfile,
stderr=logfile,
creationflags=subprocess_flags,
env=env,
)
_subprocess_container.add(proc.pid)
while proc.poll() is None:
if time.process_time() > timeout_time:
proc.terminate()
proc.communicate()
try:
logfile.seek(0, os.SEEK_END)
except io.UnsupportedOperation:
pass
logfile.write(
"\nERROR: AnyPyTools : Timeout after {:d} sec.".format(int(timeout))
)
proc.returncode = 0
break
time.sleep(0.05)
_subprocess_container.remove(proc.pid)
retcode = ctypes.c_int32(proc.returncode).value
if retcode == _KILLED_BY_ANYPYTOOLS:
logfile.write("\nAnybodycon.exe was interrupted by AnyPyTools")
elif retcode == _NO_LICENSES_AVAILABLE:
logfile.write(
"\nERROR: anybodycon.exe existed unexpectedly. "
"Return code: " + str(_NO_LICENSES_AVAILABLE) + " : No license available."
)
elif retcode:
logfile.write(
"\nERROR: AnyPyTools : anybodycon.exe exited unexpectedly."
" Return code: " + str(retcode)
)
if not keep_macrofile:
silentremove(macro_file.name)
return retcode
示例6: lets_run_a_test
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import returncode [as 别名]
def lets_run_a_test(name):
sitl_args = ['python', '-m', 'dronekit.sitl', 'copter-3.3-rc5', '-I0', '-S', '--model', 'quad', '--home=-35.363261,149.165230,584,353']
speedup = os.environ.get('TEST_SPEEDUP', '1')
rate = os.environ.get('TEST_RATE', '200')
sitl_args += ['--speedup', str(speedup), '-r', str(rate)]
newenv = os.environ.copy()
newenv['PYTHONUNBUFFERED'] = '1'
# Change CPU core affinity.
# TODO change affinity on osx/linux
if sys.platform == 'win32':
# 0x14 = 0b1110 = all cores except cpu 1
sitl = Popen(['start', '/affinity', '14', '/realtime', '/b', '/wait'] + sitl_args, shell=True, stdout=PIPE, stderr=PIPE, env=newenv)
else:
sitl = Popen(sitl_args, stdout=PIPE, stderr=PIPE, env=newenv)
bg.append(sitl)
while sitl.poll() == None:
line = sitl.stdout.readline()
if 'Waiting for connection' in line:
break
if sitl.poll() != None and sitl.returncode != 0:
print('[runner] ...aborting with SITL error code ' + str(sitl.returncode))
sys.stdout.flush()
sys.stderr.flush()
sys.exit(sitl.returncode)
if sys.platform == 'win32':
out_fd = 1
err_fd = 2
else:
out_fd = os.dup(1)
err_fd = os.dup(2)
(out_fd, out_h) = wrap_fd(out_fd)
(err_fd, err_h) = wrap_fd(err_fd)
newenv['TEST_WRITE_OUT'] = out_fd
newenv['TEST_WRITE_ERR'] = err_fd
newenv['TEST_NAME'] = name
print('[runner] ' + name, file=sys.stderr)
sys.stdout.flush()
sys.stderr.flush()
mavproxy_verbose = os.environ.get('TEST_VERBOSE', '0') != '0'
timeout = 5*60
try:
if sys.platform == 'win32':
try:
# Try to find installed Python MAVProxy module.
import imp
imp.find_module('MAVProxy')
mavprog = [sys.executable, '-m', 'MAVProxy.mavproxy']
except:
# Uses mavproxy.exe instead.
mavprog = ['mavproxy']
else:
mavprog = [sys.executable, '-m', 'MAVProxy.mavproxy']
p = Popen(mavprog + ['--logfile=' + tempfile.mkstemp()[1], '--master=tcp:127.0.0.1:5760'],
cwd=testpath, env=newenv, stdin=PIPE, stdout=PIPE,
stderr=PIPE if not mavproxy_verbose else None)
bg.append(p)
# TODO this sleep is only for us to waiting until
# all parameters to be received; would prefer to
# move this to testlib.py and happen asap
while p.poll() == None:
line = p.stdout.readline()
if mavproxy_verbose:
sys.stdout.write(line)
sys.stdout.flush()
if 'parameters' in line:
break
time.sleep(3)
# NOTE these are *very inappropriate settings*
# to make on a real vehicle. They are leveraged
# exclusively for simulation. Take heed!!!
p.stdin.write('set moddebug 3\n')
p.stdin.write('param set ARMING_CHECK 0\n')
p.stdin.write('param set FS_THR_ENABLE 0\n')
p.stdin.write('param set FS_GCS_ENABLE 0\n')
p.stdin.write('param set EKF_CHECK_THRESH 0\n')
p.stdin.write('module load droneapi.module.api\n')
p.stdin.write('api start testlib.py\n')
p.stdin.flush()
wait_timeout(p, timeout, mavproxy_verbose)
except RuntimeError:
kill(p.pid)
p.returncode = 143
print('Error: Timeout after ' + str(timeout) + ' seconds.')
bg.remove(p)
#.........这里部分代码省略.........