Skip to content

Commit

Permalink
use "with open" instead of "open" and "close"
Browse files Browse the repository at this point in the history
  • Loading branch information
bcdaniels committed Apr 13, 2022
1 parent b36ba92 commit 59b4281
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions SirIsaac/fittingProblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1801,12 +1801,11 @@ def localFitToData_parallel(self,numprocs,fittingData,dataModel,
save(inputDict,inputDictFilename)

# call mpi
stdoutFile = open(prefix+"stdout.txt",'w')
subprocess.call([ "mpirun","-np",str(numprocs),"--allow-run-as-root","python",
os.path.join(SIRISAACDIR, "localFitParallel.py"),
inputDictFilename ],
stderr=stdoutFile,stdout=stdoutFile,env=os.environ)
stdoutFile.close()
with open(prefix+"stdout.txt",'w') as stdoutFile:
subprocess.call([ "mpirun","-np",str(numprocs),"python",
os.path.join(SIRISAACDIR, "localFitParallel.py"),
inputDictFilename ],
stderr=stdoutFile,stdout=stdoutFile,env=os.environ)
os.remove(inputDictFilename)

try:
Expand Down Expand Up @@ -2622,12 +2621,11 @@ def generateEnsemble_parallel(self,numprocs,dataModel,initialParameters,
# for info on "env=os.environ", see
# https://stackoverflow.com/questions/60060142/strange-interaction-
# between-h5py-subprocess-and-mpirun
stdoutFile = open(prefix+"stdout.txt",'w')
subprocess.call([ "mpirun","-np",str(numprocs),"--allow-run-as-root","python",
os.path.join(SIRISAACDIR, "generateEnsembleParallel.py"),
inputDictFilename ],
stderr=stdoutFile,stdout=stdoutFile,env=os.environ)
stdoutFile.close()
with open(prefix+"stdout.txt",'w') as stdoutFile:
subprocess.call([ "mpirun","-np",str(numprocs),"python",
os.path.join(SIRISAACDIR, "generateEnsembleParallel.py"),
inputDictFilename ],
stderr=stdoutFile,stdout=stdoutFile,env=os.environ)
os.remove(inputDictFilename)

try:
Expand Down

0 comments on commit 59b4281

Please sign in to comment.