blob: 88a9e6a4fc7abda8fbfc8e7ef27a62f1cf8e6aba (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
from __future__ import print_function
import os
import sys
import time
import subprocess
def need_retry(text):
return 'Stack dump' in text
def retry_inf(cmd):
while True:
try:
yield subprocess.check_output(cmd, stderr=subprocess.STDOUT), None
except subprocess.CalledProcessError as e:
yield e.output, e
def retry(cmd):
for n, (out, err) in enumerate(retry_inf(cmd)):
if out:
sys.stderr.write(out)
if n > 5:
raise Exception('all retries failed')
elif need_retry(out):
time.sleep(1 + n)
elif err:
raise err
else:
return
if __name__ == '__main__':
cmd = sys.argv[1:]
if '-c' in cmd:
try:
retry(cmd)
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)
else:
os.execv(cmd[0], cmd)
|