From bd27b8132c458df5f6583369de2c90dd36ec2bbb Mon Sep 17 00:00:00 2001 From: bolliger32 Date: Mon, 3 Jun 2019 19:51:39 +0000 Subject: [PATCH 1/8] return returncode in runclaw --- src/python/clawutil/runclaw.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/python/clawutil/runclaw.py b/src/python/clawutil/runclaw.py index 3f55be3..d3f08da 100755 --- a/src/python/clawutil/runclaw.py +++ b/src/python/clawutil/runclaw.py @@ -259,6 +259,8 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, if returncode != 0: print('==> runclaw: *** fortran returncode = ', returncode, ' aborting') + + return returncode #---------------------------------------------------------- From 1d44ea3a88b34a33666e76a98f00c35baa2e3601 Mon Sep 17 00:00:00 2001 From: bolliger32 Date: Tue, 4 Jun 2019 02:20:30 +0000 Subject: [PATCH 2/8] use subprocess for runclaw --- src/python/clawutil/runclaw.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/python/clawutil/runclaw.py b/src/python/clawutil/runclaw.py index d3f08da..8599a99 100755 --- a/src/python/clawutil/runclaw.py +++ b/src/python/clawutil/runclaw.py @@ -14,10 +14,13 @@ import sys import glob import shutil +import shlex +import subprocess from clawpack.clawutil.claw_git_status import make_git_status_file def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, - rundir=None, print_git_status=False, nohup=False, nice=None): + rundir=None, print_git_status=False, nohup=False, nice=None, + stdout=None, stderr=None): """ Run the Fortran version of Clawpack using executable xclawcmd, which is typically set to 'xclaw', 'xamr', etc. @@ -45,6 +48,10 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, If type(nice) is int, runs the code using "nice -n " with this nice value so it doesn't hog computer resources. + + if stdout or stderr are not None, they must be open python file handles. + The stdout and stderr from the call to CLAW_EXE will be written to + them. """ @@ -234,20 +241,26 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, else: cmd = "nohup time %s " % xclawcmd print("\n==> Running with command:\n ", cmd) - returncode = os.system(cmd) else: if type(nice) is int: cmd = "nice -n %s %s " % (nice,xclawcmd) else: cmd = xclawcmd print("\n==> Running with command:\n ", cmd) - returncode = os.system(cmd) + + cmd_split = shlex.split(cmd) + p = subprocess.Popen(cmd_split, + stdout=stdout, + stderr=stderr, + encoding='latin-1', + bufsize=1) + p.communicate() - if returncode == 0: + if p.returncode == 0: print("\n==> runclaw: Finished executing\n") else: print("\n ==> runclaw: *** Runtime error: return code = %s\n "\ - % returncode) + % p.returncode) print('==> runclaw: Done executing %s via clawutil.runclaw.py' %\ xclawcmd) print('==> runclaw: Output is in ', outdir) @@ -257,10 +270,10 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, os.chdir(startdir) - if returncode != 0: - print('==> runclaw: *** fortran returncode = ', returncode, ' aborting') + if p.returncode != 0: + print('==> runclaw: *** fortran returncode = ', p.returncode, ' aborting') - return returncode + return p.returncode #---------------------------------------------------------- From 50b31ce790b3da6a26ccb716a42ccefca8489e79 Mon Sep 17 00:00:00 2001 From: bolliger32 Date: Mon, 17 Jun 2019 02:53:57 +0000 Subject: [PATCH 3/8] clawutil threadsafe changes --- src/python/clawutil/data.py | 24 ++- src/python/clawutil/runclaw.py | 294 ++++++++++++++------------------- src/python/clawutil/test.py | 43 +++-- 3 files changed, 167 insertions(+), 194 deletions(-) diff --git a/src/python/clawutil/data.py b/src/python/clawutil/data.py index dcfd915..edb18fd 100644 --- a/src/python/clawutil/data.py +++ b/src/python/clawutil/data.py @@ -14,6 +14,8 @@ from __future__ import absolute_import from __future__ import print_function import os +from inspect import signature + try: from urllib.request import urlopen except ImportError: @@ -458,7 +460,6 @@ def __init__(self, pkg, num_dim): import clawpack.amrclaw.data as amrclaw self.xclawcmd = 'xamr' - self.add_data(ClawInputData(num_dim),'clawdata') self.add_data(amrclaw.AmrclawInputData(self.clawdata),'amrdata') self.add_data(amrclaw.RegionData(num_dim=num_dim),'regiondata') self.add_data(amrclaw.GaugeData(num_dim=num_dim),'gaugedata') @@ -517,16 +518,25 @@ def new_UserData(self,name,fname): return data - def write(self): + def write(self, out_dir = ''): r"""Write out each data objects in datalist """ import clawpack.amrclaw.data as amrclaw for data_object in self.data_list: + # UserData doesn't naturally have an "out_file" parameter + if isinstance(data_object, UserData): + fname = data_object.__fname__ + else: + try: + fname = signature(data_object.write).parameters['out_file'].default + except: + raise ValueError(type(data_object)) + fpath = os.path.join(out_dir,fname) if isinstance(data_object, amrclaw.GaugeData): - data_object.write(self.clawdata.num_eqn, self.clawdata.num_aux) + data_object.write(self.clawdata.num_eqn, self.clawdata.num_aux, out_file=fpath) else: - data_object.write() + data_object.write(out_file=fpath) @@ -841,6 +851,8 @@ def add_param(self,name,value,descr=''): descr_dict = self.__descr__ descr_dict[name] = descr - def write(self,data_source='setrun.py'): - super(UserData,self).write(self.__fname__, data_source) + def write(self, data_source='setrun.py', out_file=None): + if out_file is None: + out_file = self.__fname__ + super(UserData,self).write(out_file, data_source) self.close_data_file() diff --git a/src/python/clawutil/runclaw.py b/src/python/clawutil/runclaw.py index 8599a99..271f925 100755 --- a/src/python/clawutil/runclaw.py +++ b/src/python/clawutil/runclaw.py @@ -18,9 +18,19 @@ import subprocess from clawpack.clawutil.claw_git_status import make_git_status_file +# define an execution error class that returns a +# message as well as the rest of the subprocess exceptions +class ClawExeError(subprocess.CalledProcessError): + def __init__(self, msg, *args, **kwargs): + super().__init__(*args, **kwargs) + self.msg = msg + + def __str__(self): + return self.msg + def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, rundir=None, print_git_status=False, nohup=False, nice=None, - stdout=None, stderr=None): + xclawout=subprocess.PIPE, xclawerr=subprocess.PIPE): """ Run the Fortran version of Clawpack using executable xclawcmd, which is typically set to 'xclaw', 'xamr', etc. @@ -49,18 +59,17 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, If type(nice) is int, runs the code using "nice -n " with this nice value so it doesn't hog computer resources. - if stdout or stderr are not None, they must be open python file handles. - The stdout and stderr from the call to CLAW_EXE will be written to - them. + xclawout and xclawerr define the locations of stdout and stderr for the + execution of CLAW_EXE. They should be strings to filepaths or open file + objects or ``subprocess.PIPE`` or ``subprocess.STDOUT``. To pass both + to the same file, specify ``xclawout`` as the filepath and + ``xclawerr=subprocess.STDOUT``. """ - from clawpack.clawutil.data import ClawData import os,glob,shutil,time verbose = True - xclawout = None - xclawerr = None - + try: nice = int(nice) except: @@ -88,7 +97,7 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, if outdir is None: outdir = '.' - + if rundir is None: rundir = os.getcwd() rundir = os.path.abspath(rundir) @@ -103,177 +112,120 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, clawdata = ClawData() clawdata.read(os.path.join(rundir,'claw.data'), force=True) restart = clawdata.restart - #print '+++ From claw.data determined restart = %s' % restart - - - #returncode = clawjob.runxclaw() - - if 1: - startdir = os.getcwd() - xdir = os.path.abspath(startdir) - outdir = os.path.abspath(outdir) - rundir = os.path.abspath(rundir) - xclawcmd = os.path.join(xdir,xclawcmd) + xclawcmd = os.path.abspath(xclawcmd) + + if os.path.isfile(outdir): + print("==> runclaw: Error: outdir specified is a file") + return + + if (os.path.isdir(outdir) & (not overwrite)): + # copy the old outdir before possibly overwriting + tm = time.localtime(os.path.getmtime(outdir)) + year = str(tm[0]).zfill(4) + month = str(tm[1]).zfill(2) + day = str(tm[2]).zfill(2) + hour = str(tm[3]).zfill(2) + minute = str(tm[4]).zfill(2) + second = str(tm[5]).zfill(2) + outdir_backup = outdir + '_%s-%s-%s-%s%s%s' \ + % (year,month,day,hour,minute,second) + if verbose: + print("==> runclaw: Directory already exists: ",os.path.split(outdir)[1]) + if restart: + print("==> runclaw: Copying directory to: ",os.path.split(outdir_backup)[1]) + else: + print("==> runclaw: Moving directory to: ",os.path.split(outdir_backup)[1]) + time.sleep(1) + try: - os.chdir(xdir) + shutil.move(outdir,outdir_backup) + if restart: + shutil.copytree(outdir_backup,outdir) except: - raise Exception( "==> runclaw: Cannot change to directory xdir = %s" %xdir) - return - - - if os.path.isfile(outdir): - print("==> runclaw: Error: outdir specified is a file") - return - - if (os.path.isdir(outdir) & (not overwrite)): - # copy the old outdir before possibly overwriting - tm = time.localtime(os.path.getmtime(outdir)) - year = str(tm[0]).zfill(4) - month = str(tm[1]).zfill(2) - day = str(tm[2]).zfill(2) - hour = str(tm[3]).zfill(2) - minute = str(tm[4]).zfill(2) - second = str(tm[5]).zfill(2) - outdir_backup = outdir + '_%s-%s-%s-%s%s%s' \ - % (year,month,day,hour,minute,second) - if verbose: - print("==> runclaw: Directory already exists: ",os.path.split(outdir)[1]) - if restart: - print("==> runclaw: Copying directory to: ",os.path.split(outdir_backup)[1]) - else: - print("==> runclaw: Moving directory to: ",os.path.split(outdir_backup)[1]) - time.sleep(1) - - try: - shutil.move(outdir,outdir_backup) - if restart: - shutil.copytree(outdir_backup,outdir) - except: - print("==> runclaw: Could not move directory... copy already exists?") - - - if (not os.path.isdir(outdir)): - try: - os.mkdir(outdir) - except: - print("Cannot make directory ",outdir) - return + print("==> runclaw: Could not move directory... copy already exists?") + - try: - os.chdir(outdir) - except: - print('==> runclaw: *** Error in runxclaw: cannot move to outdir = ',\ - outdir) - raise + os.makedirs(outdir, exist_ok=True) + + if print_git_status not in [False,'False']: + # create files claw_git_status.txt and claw_git_diffs.txt in + # outdir: + make_git_status_file(outdir=outdir) + + # old fort.* files to be removed for new run? + fortfiles = glob.glob(os.path.join(outdir,'fort.*')) + # also need to remove gauge*.txt output files now that the gauge + # output is no longer in fort.gauge (but don't remove new gauges.data) + gaugefiles = glob.glob(os.path.join(outdir,'gauge*.txt')) + + if (overwrite and (not restart)): + # remove any old versions: + if verbose: + print("==> runclaw: Removing all old fort/gauge files in ", outdir) + for file in fortfiles + gaugefiles: + os.remove(file) + elif restart: + if verbose: + print("==> runclaw: Restart: leaving original fort/gauge files in ", outdir) + else: + # this should never be reached: + # if overwrite==False then outdir has already been moved + if len(fortfiles+gaugefiles) > 1: + print("==> runclaw: *** Remove fort.* and gauge*.txt") + print(" from output directory %s and try again," % outdir) + print(" or use overwrite=True in call to runclaw") + print(" e.g., by setting OVERWRITE = True in Makefile") return - - if print_git_status not in [False,'False']: - # create files claw_git_status.txt and claw_git_diffs.txt in - # outdir: - make_git_status_file() - - # old fort.* files to be removed for new run? - fortfiles = glob.glob(os.path.join(outdir,'fort.*')) - # also need to remove gauge*.txt output files now that the gauge - # output is no longer in fort.gauge (but don't remove new gauges.data) - gaugefiles = glob.glob(os.path.join(outdir,'gauge*.txt')) - - if (overwrite and (not restart)): - # remove any old versions: - if verbose: - print("==> runclaw: Removing all old fort/gauge files in ", outdir) - for file in fortfiles + gaugefiles: - os.remove(file) - elif restart: - if verbose: - print("==> runclaw: Restart: leaving original fort/gauge files in ", outdir) + + datafiles = glob.glob(os.path.join(rundir,'*.data')) + if datafiles == (): + print("==> runclaw: Warning: no data files found in directory ",rundir) + else: + if rundir != outdir: + for file in datafiles: + shutil.copy(file,os.path.join(outdir,os.path.basename(file))) + + # execute command to run fortran program: + if nohup: + # run in nohup mode: + print("\n==> Running in nohup mode, output will be sent to:") + print(" %s/nohup.out" % outdir) + if type(nice) is int: + cmd = "nohup time nice -n %s %s " % (nice,xclawcmd) else: - # this should never be reached: - # if overwrite==False then outdir has already been moved - if len(fortfiles+gaugefiles) > 1: - print("==> runclaw: *** Remove fort.* and gauge*.txt") - print(" from output directory %s and try again," % outdir) - print(" or use overwrite=True in call to runclaw") - print(" e.g., by setting OVERWRITE = True in Makefile") - return - - - try: - os.chdir(rundir) - except: - raise Exception("Cannot change to directory %s" % rundir) - return - - datafiles = glob.glob('*.data') - if datafiles == (): - print("==> runclaw: Warning: no data files found in directory ",rundir) + cmd = "nohup time %s " % xclawcmd + print("\n==> Running with command:\n ", cmd) + else: + if type(nice) is int: + cmd = "nice -n %s %s " % (nice,xclawcmd) else: - if rundir != outdir: - for file in datafiles: - shutil.copy(file,os.path.join(outdir,file)) - - if xclawout: - xclawout = open(xclawout,'wb') - if xclawerr: - xclawerr = open(xclawerr,'wb') - - os.chdir(outdir) - - #print "\nIn directory outdir = ",outdir,"\n" - - # execute command to run fortran program: - - try: - #print "\nExecuting ",xclawcmd, " ... " - #pclaw = subprocess.Popen(xclawcmd,stdout=xclawout,stderr=xclawerr) - #print '+++ pclaw started' - #pclaw.wait() # wait for code to run - #returncode = pclaw.returncode - #print '+++ pclaw done' - - if nohup: - # run in nohup mode: - print("\n==> Running in nohup mode, output will be sent to:") - print(" %s/nohup.out" % outdir) - if type(nice) is int: - cmd = "nohup time nice -n %s %s " % (nice,xclawcmd) - else: - cmd = "nohup time %s " % xclawcmd - print("\n==> Running with command:\n ", cmd) - else: - if type(nice) is int: - cmd = "nice -n %s %s " % (nice,xclawcmd) - else: - cmd = xclawcmd - print("\n==> Running with command:\n ", cmd) - - cmd_split = shlex.split(cmd) - p = subprocess.Popen(cmd_split, - stdout=stdout, - stderr=stderr, - encoding='latin-1', - bufsize=1) - p.communicate() - - if p.returncode == 0: - print("\n==> runclaw: Finished executing\n") - else: - print("\n ==> runclaw: *** Runtime error: return code = %s\n "\ - % p.returncode) - print('==> runclaw: Done executing %s via clawutil.runclaw.py' %\ - xclawcmd) - print('==> runclaw: Output is in ', outdir) - - except: - raise Exception("Could not execute command %s" % xclawcmd) + cmd = xclawcmd + print("\n==> Running with command:\n ", cmd) + + cmd_split = shlex.split(cmd) + if isinstance(xclawout,str): + xclawout = open(xclawout,'w', encoding='utf-8') + if isinstance(xclawerr,str): + xclawerr = open(xclawerr,'w', encoding='utf-8') + try: + p = subprocess.run(cmd_split, + cwd=outdir, + stdout=xclawout, + stderr=xclawerr, + encoding='utf-8', + bufsize=1, + check=True) + except subprocess.CalledProcessError as cpe: + raise ClawExeError('error', cpe.returncode, cpe.cmd, + output=cpe.output, + stderr=cpe.stderr) from cpe - os.chdir(startdir) + print('==> runclaw: Done executing %s via clawutil.runclaw.py' %\ + xclawcmd) + print('==> runclaw: Output is in ', outdir) - if p.returncode != 0: - print('==> runclaw: *** fortran returncode = ', p.returncode, ' aborting') - - return p.returncode + return p #---------------------------------------------------------- diff --git a/src/python/clawutil/test.py b/src/python/clawutil/test.py index bddde4a..5c0289c 100644 --- a/src/python/clawutil/test.py +++ b/src/python/clawutil/test.py @@ -25,6 +25,7 @@ import clawpack.pyclaw.gauges as gauges import clawpack.pyclaw.solution as solution import clawpack.clawutil.claw_git_status as claw_git_status +from clawpack.clawutil import runclaw # Support for WIP decorator from functools import wraps @@ -214,28 +215,36 @@ def write_rundata_objects(self, path=None): if path is None: path = self.temp_path - - orig_path = os.getcwd() - os.chdir(path) - self.rundata.write() - os.chdir(orig_path) + self.rundata.write(out_dir=path) def run_code(self): r"""Run test code given an already compiled executable""" - runclaw_cmd = " ".join(( - "cd %s ;" % self.temp_path, - "python", - "$CLAW/clawutil/src/python/clawutil/runclaw.py", - self.executable_name, - self.temp_path, - "True", - "False", - self.temp_path)) - subprocess.check_call(runclaw_cmd, stdout=self.stdout, - stderr=self.stderr, - shell=True) +# runclaw_cmd = " ".join(( +# "cd %s ;" % self.temp_path, +# "python", +# "$CLAW/clawutil/src/python/clawutil/runclaw.py", +# self.executable_name, +# self.temp_path, +# "True", +# "False", +# self.temp_path, +# os.path.join(self.temp_path,'geoclaw.out'), +# os.path.join(self.temp_path,'geoclaw.err'))) + this_dir = os.getcwd() + os.chdir(self.temp_path) + runclaw.runclaw(xclawcmd=os.path.join(self.temp_path,self.executable_name), + rundir=self.temp_path, + outdir=self.temp_path, + overwrite=True, + restart=False, + xclawout=self.stdout, + xclawerr=self.stderr) + os.chdir(this_dir) +# subprocess.check_call(runclaw_cmd, stdout=self.stdout, +# stderr=self.stderr, +# shell=True) self.stdout.flush() self.stderr.flush() From faf1f0112d6f3928e0971b2cd4da65005b3bb424 Mon Sep 17 00:00:00 2001 From: bolliger32 Date: Mon, 17 Jun 2019 02:57:55 +0000 Subject: [PATCH 4/8] chdir in test --- src/python/clawutil/test.py | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/python/clawutil/test.py b/src/python/clawutil/test.py index 5c0289c..76a181f 100644 --- a/src/python/clawutil/test.py +++ b/src/python/clawutil/test.py @@ -220,19 +220,8 @@ def write_rundata_objects(self, path=None): def run_code(self): r"""Run test code given an already compiled executable""" - -# runclaw_cmd = " ".join(( -# "cd %s ;" % self.temp_path, -# "python", -# "$CLAW/clawutil/src/python/clawutil/runclaw.py", -# self.executable_name, -# self.temp_path, -# "True", -# "False", -# self.temp_path, -# os.path.join(self.temp_path,'geoclaw.out'), -# os.path.join(self.temp_path,'geoclaw.err'))) - this_dir = os.getcwd() + + cwd = os.getcwd() os.chdir(self.temp_path) runclaw.runclaw(xclawcmd=os.path.join(self.temp_path,self.executable_name), rundir=self.temp_path, @@ -241,10 +230,8 @@ def run_code(self): restart=False, xclawout=self.stdout, xclawerr=self.stderr) - os.chdir(this_dir) -# subprocess.check_call(runclaw_cmd, stdout=self.stdout, -# stderr=self.stderr, -# shell=True) + os.chdir(cwd) + self.stdout.flush() self.stderr.flush() @@ -264,12 +251,15 @@ def runTest(self, save=False, indices=(2, 3)): """ # Write out data files + cwd = os.getcwd() + os.chdir(self.temp_path) self.load_rundata() self.write_rundata_objects() # Run code self.run_code() - + os.chdir(cwd) + # Perform tests # Override this class to perform data checks, as is this class will # simply check that a test runs to completion From 4147443b3cd477fd25919bc978c9487d44e81b2d Mon Sep 17 00:00:00 2001 From: bolliger32 Date: Mon, 17 Jun 2019 03:32:29 +0000 Subject: [PATCH 5/8] switch test chdir location --- src/python/clawutil/test.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/python/clawutil/test.py b/src/python/clawutil/test.py index 76a181f..55fd5ad 100644 --- a/src/python/clawutil/test.py +++ b/src/python/clawutil/test.py @@ -215,14 +215,17 @@ def write_rundata_objects(self, path=None): if path is None: path = self.temp_path + # need to cwd b/c setrun.py files contain + # relative paths to topofiles and fgmax files + cwd = os.getcwd() + os.chdir(path) self.rundata.write(out_dir=path) + os.chdir(cwd) def run_code(self): r"""Run test code given an already compiled executable""" - - cwd = os.getcwd() - os.chdir(self.temp_path) + runclaw.runclaw(xclawcmd=os.path.join(self.temp_path,self.executable_name), rundir=self.temp_path, outdir=self.temp_path, @@ -230,7 +233,6 @@ def run_code(self): restart=False, xclawout=self.stdout, xclawerr=self.stderr) - os.chdir(cwd) self.stdout.flush() self.stderr.flush() @@ -251,14 +253,11 @@ def runTest(self, save=False, indices=(2, 3)): """ # Write out data files - cwd = os.getcwd() - os.chdir(self.temp_path) self.load_rundata() self.write_rundata_objects() # Run code self.run_code() - os.chdir(cwd) # Perform tests # Override this class to perform data checks, as is this class will From 36f1cca529dcecbf89a38a64451e76fdc884aa7a Mon Sep 17 00:00:00 2001 From: bolliger32 Date: Mon, 17 Jun 2019 05:37:40 +0000 Subject: [PATCH 6/8] remove chdir b/c now in write methods --- src/python/clawutil/test.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/python/clawutil/test.py b/src/python/clawutil/test.py index 55fd5ad..45e2eef 100644 --- a/src/python/clawutil/test.py +++ b/src/python/clawutil/test.py @@ -215,12 +215,7 @@ def write_rundata_objects(self, path=None): if path is None: path = self.temp_path - # need to cwd b/c setrun.py files contain - # relative paths to topofiles and fgmax files - cwd = os.getcwd() - os.chdir(path) self.rundata.write(out_dir=path) - os.chdir(cwd) def run_code(self): From 00d322a3b6a35c5db0336c64018bbda07b139f13 Mon Sep 17 00:00:00 2001 From: bolliger32 Date: Mon, 17 Jun 2019 06:15:50 +0000 Subject: [PATCH 7/8] remove unnecessary try except --- src/python/clawutil/data.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/python/clawutil/data.py b/src/python/clawutil/data.py index edb18fd..276a0df 100644 --- a/src/python/clawutil/data.py +++ b/src/python/clawutil/data.py @@ -528,10 +528,7 @@ def write(self, out_dir = ''): if isinstance(data_object, UserData): fname = data_object.__fname__ else: - try: - fname = signature(data_object.write).parameters['out_file'].default - except: - raise ValueError(type(data_object)) + fname = signature(data_object.write).parameters['out_file'].default fpath = os.path.join(out_dir,fname) if isinstance(data_object, amrclaw.GaugeData): data_object.write(self.clawdata.num_eqn, self.clawdata.num_aux, out_file=fpath) From 10edc50de410eeaa768932af89540cee45476d27 Mon Sep 17 00:00:00 2001 From: bolliger32 Date: Wed, 19 Jun 2019 03:33:01 +0000 Subject: [PATCH 8/8] fix buffering --- src/python/clawutil/runclaw.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/python/clawutil/runclaw.py b/src/python/clawutil/runclaw.py index 271f925..8d8f4d3 100755 --- a/src/python/clawutil/runclaw.py +++ b/src/python/clawutil/runclaw.py @@ -205,16 +205,17 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, cmd_split = shlex.split(cmd) if isinstance(xclawout,str): - xclawout = open(xclawout,'w', encoding='utf-8') + xclawout = open(xclawout,'w', encoding='utf-8', + buffering=1) if isinstance(xclawerr,str): - xclawerr = open(xclawerr,'w', encoding='utf-8') + xclawerr = open(xclawerr,'w', encoding='utf-8', + buffering=1) try: p = subprocess.run(cmd_split, cwd=outdir, stdout=xclawout, stderr=xclawerr, encoding='utf-8', - bufsize=1, check=True) except subprocess.CalledProcessError as cpe: raise ClawExeError('error', cpe.returncode, cpe.cmd,