Skip to content

Commit 09a2f9b

Browse files
committedApr 18, 2016
[Processing] Retry gdal commands if they are interrupted
1 parent 7cb77d8 commit 09a2f9b

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed
 

‎python/plugins/processing/algs/gdal/GdalUtils.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,34 @@ def runGdal(commands, progress=None):
6767
envval += '{}{}'.format(os.pathsep, path)
6868
os.putenv('PATH', envval)
6969

70-
loglines = []
71-
loglines.append('GDAL execution console output')
7270
fused_command = ' '.join([unicode(c) for c in commands])
7371
progress.setInfo('GDAL command:')
7472
progress.setCommand(fused_command)
75-
proc = subprocess.Popen(
76-
fused_command,
77-
shell=True,
78-
stdout=subprocess.PIPE,
79-
stdin=open(os.devnull),
80-
stderr=subprocess.STDOUT,
81-
universal_newlines=True,
82-
).stdout
8373
progress.setInfo('GDAL command output:')
84-
try:
85-
for line in proc:
86-
progress.setConsoleInfo(line)
87-
loglines.append(line)
88-
except IOError as e:
89-
raise IOError(e.message + u'\nAfter reading {} lines, last lines: {}'.format(len(loglines), u'\n'.join(loglines[-10:])))
74+
success = False
75+
retry_count = 0
76+
while success == False:
77+
loglines = []
78+
loglines.append('GDAL execution console output')
79+
try:
80+
proc = subprocess.Popen(
81+
fused_command,
82+
shell=True,
83+
stdout=subprocess.PIPE,
84+
stdin=open(os.devnull),
85+
stderr=subprocess.STDOUT,
86+
universal_newlines=True,
87+
).stdout
88+
for line in proc:
89+
progress.setConsoleInfo(line)
90+
loglines.append(line)
91+
success = True
92+
except IOError as e:
93+
if retry_count < 5:
94+
retry_count += 1
95+
else:
96+
raise IOError(e.message + u'\nTried 5 times without success. Last iteration stopped after reading {} line(s).\nLast line(s):\n{}'.format(len(loglines), u'\n'.join(loglines[-10:])))
97+
9098
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
9199
GdalUtils.consoleOutput = loglines
92100

0 commit comments

Comments
 (0)
Please sign in to comment.