Skip to content

Commit

Permalink
[processing] Avoid python hangs when run in headless mode from FCGI
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Oct 3, 2014
1 parent 0d5fb23 commit 59ec15b
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/GdalUtils.py
Expand Up @@ -73,7 +73,7 @@ def runGdal(commands, progress):
fused_command,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=False,
).stdout
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/grass/GrassUtils.py
Expand Up @@ -270,7 +270,7 @@ def executeGrass(commands, progress, outputCommands=None):
command,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=True,
).stdout
Expand Down Expand Up @@ -299,7 +299,7 @@ def executeGrass(commands, progress, outputCommands=None):
command,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=True,
).stdout
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/grass7/Grass7Utils.py
Expand Up @@ -272,7 +272,7 @@ def executeGrass7(commands, progress, outputCommands=None):
command,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=True,
).stdout
Expand Down Expand Up @@ -301,7 +301,7 @@ def executeGrass7(commands, progress, outputCommands=None):
command,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=True,
).stdout
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/lidar/fusion/FusionUtils.py
Expand Up @@ -67,7 +67,7 @@ def runFusion(commands, progress):
commands,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=False,
).stdout
Expand Down
Expand Up @@ -46,7 +46,7 @@ def runLAStools(commands, progress):
loglines = []
loglines.append("LAStools console output")
commandline = " ".join(commands)
proc = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
proc = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stdin=open(os.devnull),
stderr=subprocess.STDOUT, universal_newlines=False).stdout
for line in iter(proc.readline, ""):
loglines.append(line)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/otb/OTBUtils.py
Expand Up @@ -131,7 +131,7 @@ def executeOtb(commands, progress):
loglines.append("OTB execution console output")
os.putenv('ITK_AUTOLOAD_PATH', OTBUtils.otbLibPath())
fused_command = ''.join(['"%s" ' % c for c in commands])
proc = subprocess.Popen(fused_command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout
proc = subprocess.Popen(fused_command, shell=True, stdout=subprocess.PIPE, stdin=open(os.devnull),stderr=subprocess.STDOUT, universal_newlines=True).stdout
for line in iter(proc.readline, ""):
if "[*" in line:
idx = line.find("[*")
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/r/RUtils.py
Expand Up @@ -103,7 +103,7 @@ def executeRAlgorithm(alg, progress):
command,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=True,
)
Expand Down Expand Up @@ -171,7 +171,7 @@ def checkRIsInstalled(ignoreRegistrySettings=False):
command,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=True,
).stdout
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/saga/SagaDescriptionCreator.py
Expand Up @@ -41,7 +41,7 @@ def createLibraryFiles(self):
command,
shell=True,
stdout=f2,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=True,
)
Expand Down Expand Up @@ -77,7 +77,7 @@ def createDescriptionFiles(self):
command,
shell=True,
stdout=f,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=f,
universal_newlines=True,
)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/saga/SagaUtils.py
Expand Up @@ -128,7 +128,7 @@ def executeSaga(progress):
command,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=True,
).stdout
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/taudem/TauDEMUtils.py
Expand Up @@ -86,7 +86,7 @@ def executeTauDEM(command, progress):
fused_command,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=True,
).stdout
Expand Down
21 changes: 12 additions & 9 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -323,20 +323,23 @@ def runAlgorithm(algOrName, onFinish, *args):
print 'Warning: Not all input layers use the same CRS.\n' \
+ 'This can cause unexpected results.'

# Don't set the wait cursor twice, because then when you
# restore it, it will still be a wait cursor.
cursor = QApplication.overrideCursor()
if cursor is None or cursor == 0:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
elif cursor.shape() != Qt.WaitCursor:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
if iface is not None:
# Don't set the wait cursor twice, because then when you
# restore it, it will still be a wait cursor.
cursor = QApplication.overrideCursor()
if cursor is None or cursor == 0:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
elif cursor.shape() != Qt.WaitCursor:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

progress = None
if iface is not None :
progress = MessageBarProgress()
ret = runalg(alg, progress)
if onFinish is not None and ret:
onFinish(alg, progress)
QApplication.restoreOverrideCursor()
progress.close()

if iface is not None:
QApplication.restoreOverrideCursor()
progress.close()
return alg

0 comments on commit 59ec15b

Please sign in to comment.