本文整理汇总了Python中subprocess32.TimeoutExpired方法的典型用法代码示例。如果您正苦于以下问题:Python subprocess32.TimeoutExpired方法的具体用法?Python subprocess32.TimeoutExpired怎么用?Python subprocess32.TimeoutExpired使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess32
的用法示例。
在下文中一共展示了subprocess32.TimeoutExpired方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exec_command
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import TimeoutExpired [as 别名]
def exec_command(cmd, args, cwd, timeout=None):
"""
Executes shell command inside @repo_path
returns exec code
"""
pipe = None
try:
env = os.environ
env["PATH"] = env["NDK_TOOLCHAIN"] + "/bin:" + env["PATH"]
pipe = Popen(args, stdin=PIPE, stdout=PIPE, cwd=cwd, env=env)
stdout, error = pipe.communicate(timeout=timeout) if (timeout and timeout > 0) else pipe.communicate()
logger.debug("stdout: %s", stdout)
return pipe.returncode
except TimeoutExpired as te:
pipe.terminate()
logger.error("%s timed out: %s", cmd, str(te))
return 0
except Exception as e:
logger.error("%s subprocess failed: %s", cmd, str(e))
return -1
示例2: adb_pushfile
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import TimeoutExpired [as 别名]
def adb_pushfile(adb, filepath, remote_path):
filesize = os.path.getsize(filepath)
pb = tqdm.tqdm(unit='B', unit_scale=True, total=filesize)
p = adb.raw_cmd('push', filepath, remote_path)
while True:
try:
p.wait(0.5)
except subprocess.TimeoutExpired:
pb.n = get_file_size(adb, remote_path)
pb.refresh()
# log.info("Progress %dM/%dM", get_file_size(remote_path) >>20, filesize >>20)
pass
except (KeyboardInterrupt, SystemExit):
p.kill()
raise
except:
raise
else:
# log.info("Success pushed into device")
break
pb.close()
示例3: run_in_subprocess
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import TimeoutExpired [as 别名]
def run_in_subprocess(cmd, check_output=False, **kwargs):
"""
Execute command using default subprocess configuration.
Parameters
----------
cmd : string
Command to be executed in subprocess.
kwargs : keywords
Options to pass to subprocess.Popen.
Returns
-------
proc : Popen subprocess
Subprocess used to run command.
"""
logger.debug('Executing command: {0}'.format(cmd))
config = DEFAULT_SUBPROCESS_CONFIG.copy()
config.update(kwargs)
if not check_output:
if omniduct_config.logging_level < 20:
config['stdout'] = None
config['stderr'] = None
else:
config['stdout'] = open(os.devnull, 'w')
config['stderr'] = open(os.devnull, 'w')
timeout = config.pop('timeout', None)
process = subprocess.Popen(cmd, **config)
try:
stdout, stderr = process.communicate(None, timeout=timeout)
except subprocess.TimeoutExpired:
os.killpg(os.getpgid(process.pid), signal.SIGINT) # send signal to the process group, recursively killing all children
output, unused_err = process.communicate()
raise subprocess.TimeoutExpired(process.args, timeout, output=output)
return SubprocessResults(returncode=process.returncode, stdout=stdout or b'', stderr=stderr or b'')
示例4: subproc_call
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import TimeoutExpired [as 别名]
def subproc_call(cmd, timeout=None):
try:
output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT,
shell=True, timeout=timeout)
return output
except subprocess.TimeoutExpired as e:
logger.warn("Command timeout!")
logger.warn(e.output)
except subprocess.CalledProcessError as e:
logger.warn("Commnad failed: {}".format(e.returncode))
logger.warn(e.output)
示例5: run_proc_with_quit
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import TimeoutExpired [as 别名]
def run_proc_with_quit(proc_id, quit_dict, args, logfile=None, append=False, env=None, cwd=None):
if logfile is None:
logfile = os.devnull
mode = 'ab' if append else 'wb'
with open(logfile, mode) as logf:
if proc_id in quit_dict:
return None
proc = subprocess.Popen(args, stdout=logf, stderr=subprocess.STDOUT,
env=env, cwd=cwd)
retcode = None
num_kill = 0
timeout = 0.05
while retcode is None and num_kill <= 2:
try:
retcode = proc.wait(timeout=timeout)
except subprocess.TimeoutExpired:
if proc_id in quit_dict:
if num_kill == 0:
proc.terminate()
timeout = quit_dict[proc_id]
elif num_kill == 1:
proc.kill()
num_kill += 1
return proc.returncode
示例6: _end_process
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import TimeoutExpired [as 别名]
def _end_process(process):
"""End a process gently or, if necessary, forcibly."""
try:
process.terminate()
process.wait(timeout=0.5)
except OSError:
pass # Can't kill things that have changed UID.
except subprocess32.TimeoutExpired:
process.kill()
示例7: subproc_call
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import TimeoutExpired [as 别名]
def subproc_call(cmd, timeout=None):
"""Execute a command with timeout, and return both STDOUT/STDERR.
Args:
cmd (str): the command to execute.
timeout (float): timeout in seconds.
Returns:
output (bytes), retcode(int): If timeout, retcode is -1.
"""
try:
output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT,
shell=True, timeout=timeout)
return output, 0
except subprocess.TimeoutExpired as e:
print("Command '{}' timeout!".format(cmd))
print(e.output.decode('utf-8'))
return e.output, -1
except subprocess.CalledProcessError as e:
print("Command '{}' failed, return code={}".format(cmd, e.returncode))
print(e.output.decode('utf-8'))
return e.output, e.returncode
except Exception:
print("Command '{}' failed to run.".format(cmd))
return "", -2
示例8: subproc_call
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import TimeoutExpired [as 别名]
def subproc_call(cmd, timeout=None):
"""
Execute a command with timeout, and return both STDOUT/STDERR.
Args:
cmd(str): the command to execute.
timeout(float): timeout in seconds.
Returns:
output(bytes), retcode(int). If timeout, retcode is -1.
"""
try:
output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT,
shell=True, timeout=timeout)
return output, 0
except subprocess.TimeoutExpired as e:
logger.warn("Command '{}' timeout!".format(cmd))
logger.warn(e.output.decode('utf-8'))
return e.output, -1
except subprocess.CalledProcessError as e:
logger.warn("Command '{}' failed, return code={}".format(cmd, e.returncode))
logger.warn(e.output.decode('utf-8'))
return e.output, e.returncode
except Exception:
logger.warn("Command '{}' failed to run.".format(cmd))
return "", -2
示例9: _grep_for_dep_lines
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import TimeoutExpired [as 别名]
def _grep_for_dep_lines(self, query_str, include_globs, exclude_globs):
arg_list =['zipgrep', query_str, self.temp_file_name]
arg_list += include_globs
arg_list.append("-x")
arg_list += exclude_globs
start = time()
try:
print "Running zipgrep: '{}'".format(" ".join(arg_list))
self.dep_lines = subprocess32.check_output(
arg_list,
timeout=90
)
except subprocess32.CalledProcessError:
# heroku throws an error here when there are no dep lines to find.
# but it's fine. there just aren't no lines.
pass
except subprocess32.TimeoutExpired:
# too many files, we'll skip it and move on.
self.error = "grep_timeout"
pass
finally:
self.grep_elapsed = elapsed(start, 4)
#print "found these dep lines: {}".format(self.dep_lines)
print "finished dep lines search in {} sec".format(self.grep_elapsed)
示例10: _launch_webdriver
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import TimeoutExpired [as 别名]
def _launch_webdriver(self):
print("start chromedriver instance")
p = subprocess.Popen(['chromedriver', '--port='+str(self._port)])
try:
p.wait(timeout=2.0)
return False
except subprocess.TimeoutExpired:
return True
示例11: watcher_getter
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import TimeoutExpired [as 别名]
def watcher_getter(request, services_log):
"""Popen object of given executable name and it's arguments.
Wait for the process to start.
Add finalizer to properly stop it.
"""
orig_request = request
def watcher_getter_function(name, arguments=None, kwargs=None, timeout=20, checker=None, request=None):
if request is None:
warnings.warn('Omitting the `request` parameter will result in an unstable order of finalizers.')
request = orig_request
executable = find_executable(name)
assert executable, 'You have to install {0} executable.'.format(name)
cmd = [name] + (arguments or [])
services_log.debug('Starting {0}: {1}'.format(name, arguments))
watcher = subprocess.Popen(
cmd, **(kwargs or {}))
def finalize():
try:
watcher.terminate()
except OSError:
pass
if watcher.returncode is None:
try:
watcher.communicate(timeout=timeout / 2)
except subprocess.TimeoutExpired:
watcher.kill()
watcher.communicate(timeout=timeout / 2)
request.addfinalizer(finalize)
# Wait for the service to start.
times = 0
while not checker():
if watcher.returncode is not None:
raise Exception("Error running {0}".format(name))
if times > timeout:
raise Exception('The {0} service checked did not succeed!'.format(name))
time.sleep(1)
times += 1
return watcher
return watcher_getter_function