mirror of
https://github.com/qgis/QGIS.git
synced 2025-06-01 00:02:16 -04:00
[Processing] Retry gdal commands if they are interrupted
This commit is contained in:
parent
7cb77d8cfd
commit
09a2f9b343
@ -67,26 +67,34 @@ class GdalUtils:
|
||||
envval += '{}{}'.format(os.pathsep, path)
|
||||
os.putenv('PATH', envval)
|
||||
|
||||
loglines = []
|
||||
loglines.append('GDAL execution console output')
|
||||
fused_command = ' '.join([unicode(c) for c in commands])
|
||||
progress.setInfo('GDAL command:')
|
||||
progress.setCommand(fused_command)
|
||||
proc = subprocess.Popen(
|
||||
fused_command,
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stdin=open(os.devnull),
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True,
|
||||
).stdout
|
||||
progress.setInfo('GDAL command output:')
|
||||
try:
|
||||
for line in proc:
|
||||
progress.setConsoleInfo(line)
|
||||
loglines.append(line)
|
||||
except IOError as e:
|
||||
raise IOError(e.message + u'\nAfter reading {} lines, last lines: {}'.format(len(loglines), u'\n'.join(loglines[-10:])))
|
||||
success = False
|
||||
retry_count = 0
|
||||
while success == False:
|
||||
loglines = []
|
||||
loglines.append('GDAL execution console output')
|
||||
try:
|
||||
proc = subprocess.Popen(
|
||||
fused_command,
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stdin=open(os.devnull),
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True,
|
||||
).stdout
|
||||
for line in proc:
|
||||
progress.setConsoleInfo(line)
|
||||
loglines.append(line)
|
||||
success = True
|
||||
except IOError as e:
|
||||
if retry_count < 5:
|
||||
retry_count += 1
|
||||
else:
|
||||
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:])))
|
||||
|
||||
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
|
||||
GdalUtils.consoleOutput = loglines
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user