def runTarsnap(args, timeout = None):
command = [config.tarsnap_bin] + config.tarsnap_extra_args + args
proc = subprocess.Popen(command,
stdout = subprocess.PIPE, stderr = subprocess.PIPE,
stdin = subprocess.DEVNULL, universal_newlines = True)
result = CheapoCompletedProcess()
try:
result.stdout, result.stderr = proc.communicate(timeout = timeout)
result.returncode = proc.wait()
if result.returncode:
sys.exit("Error running tarsnap:\nCommand: {}\nSTDOUT:\n{}\nSTDERR:\n{}\n".format(" ".join(command),result.stdout,result.stderr))
return result
except subprocess.TimeoutExpired:
print("Tarsnap timed out, sending SIGQUIT...")
proc.send_signal(signal.SIGQUIT)
result.stdout, result.stderr = proc.communicate()
result.returncode = proc.wait()
print("Tarsnap finished")
if result.returncode:
sys.exit("Error running tarsnap:\nCommand: {}\nSTDOUT:\n{}\nSTDERR:\n{}\n".format(" ".join(command),result.stdout,result.stderr))
return result
评论列表
文章目录