@@ -254,26 +254,26 @@ def executeGrass7(commands, progress, outputCommands=None):
254
254
loglines .append (Grass7Utils .tr ('GRASS GIS 7 execution console output' ))
255
255
grassOutDone = False
256
256
command , grassenv = Grass7Utils .prepareGrass7Execution (commands )
257
- proc = subprocess .Popen (
257
+ with subprocess .Popen (
258
258
command ,
259
259
shell = True ,
260
260
stdout = subprocess .PIPE ,
261
261
stdin = subprocess .DEVNULL ,
262
262
stderr = subprocess .STDOUT ,
263
263
universal_newlines = True ,
264
264
env = grassenv
265
- ). stdout
266
- for line in iter (proc .readline , '' ):
267
- if 'GRASS_INFO_PERCENT' in line :
268
- try :
269
- progress .setPercentage (int (line [len ('GRASS_INFO_PERCENT' ) + 2 :]))
270
- except :
271
- pass
272
- else :
273
- if 'r.out' in line or 'v.out' in line :
274
- grassOutDone = True
275
- loglines .append (line )
276
- progress .setConsoleInfo (line )
265
+ ) as proc :
266
+ for line in iter (proc . stdout .readline , '' ):
267
+ if 'GRASS_INFO_PERCENT' in line :
268
+ try :
269
+ progress .setPercentage (int (line [len ('GRASS_INFO_PERCENT' ) + 2 :]))
270
+ except :
271
+ pass
272
+ else :
273
+ if 'r.out' in line or 'v.out' in line :
274
+ grassOutDone = True
275
+ loglines .append (line )
276
+ progress .setConsoleInfo (line )
277
277
278
278
# Some GRASS scripts, like r.mapcalculator or r.fillnulls, call
279
279
# other GRASS scripts during execution. This may override any
@@ -283,25 +283,25 @@ def executeGrass7(commands, progress, outputCommands=None):
283
283
284
284
if not grassOutDone and outputCommands :
285
285
command , grassenv = Grass7Utils .prepareGrass7Execution (outputCommands )
286
- proc = subprocess .Popen (
286
+ with subprocess .Popen (
287
287
command ,
288
288
shell = True ,
289
289
stdout = subprocess .PIPE ,
290
290
stdin = subprocess .DEVNULL ,
291
291
stderr = subprocess .STDOUT ,
292
292
universal_newlines = True ,
293
293
env = grassenv
294
- ). stdout
295
- for line in iter (proc .readline , '' ):
296
- if 'GRASS_INFO_PERCENT' in line :
297
- try :
298
- progress .setPercentage (int (
299
- line [len ('GRASS_INFO_PERCENT' ) + 2 :]))
300
- except :
301
- pass
302
- else :
303
- loglines .append (line )
304
- progress .setConsoleInfo (line )
294
+ ) as proc :
295
+ for line in iter (proc . stdout .readline , '' ):
296
+ if 'GRASS_INFO_PERCENT' in line :
297
+ try :
298
+ progress .setPercentage (int (
299
+ line [len ('GRASS_INFO_PERCENT' ) + 2 :]))
300
+ except :
301
+ pass
302
+ else :
303
+ loglines .append (line )
304
+ progress .setConsoleInfo (line )
305
305
306
306
if ProcessingConfig .getSetting (Grass7Utils .GRASS_LOG_CONSOLE ):
307
307
ProcessingLog .addToLog (ProcessingLog .LOG_INFO , loglines )
0 commit comments