Skip to content
Permalink
Browse files

[processing] Return log lines from GdalUtils.runGdal instead of storing

in a class member

The previous approach was NOT thread safe, and it's easy to avoid
  • Loading branch information
nyalldawson committed Jan 8, 2021
1 parent 02f861c commit e79922b2ccb9da081012e2e16cc8feae40389d60
@@ -97,8 +97,7 @@ def runGdal(commands, feedback=None):
success = False
retry_count = 0
while not success:
loglines = []
loglines.append(GdalUtils.tr('GDAL execution console output'))
loglines = [GdalUtils.tr('GDAL execution console output')]
try:
with subprocess.Popen(
fused_command,
@@ -121,11 +120,7 @@ def runGdal(commands, feedback=None):
len(loglines), u'\n'.join(loglines[-10:])))

QgsMessageLog.logMessage('\n'.join(loglines), 'Processing', Qgis.Info)
GdalUtils.consoleOutput = loglines

@staticmethod
def getConsoleOutput():
return GdalUtils.consoleOutput
return loglines

@staticmethod
def getSupportedRasters():
@@ -115,11 +115,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]

def processAlgorithm(self, parameters, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
console_output = GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
output = self.parameterAsFileOutput(parameters, self.OUTPUT, context)
with open(output, 'w') as f:
f.write('<pre>')
for s in GdalUtils.getConsoleOutput()[1:]:
for s in console_output[1:]:
f.write(str(s))
f.write('</pre>')

@@ -85,11 +85,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]

def processAlgorithm(self, parameters, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
console_output = GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
output = self.parameterAsFileOutput(parameters, self.OUTPUT, context)
with open(output, 'w') as f:
f.write('<pre>')
for s in GdalUtils.getConsoleOutput()[1:]:
for s in console_output[1:]:
f.write(str(s))
f.write('</pre>')

0 comments on commit e79922b

Please sign in to comment.
You can’t perform that action at this time.