From 581d874820f8ba11804807bc21098ec43a39f44c Mon Sep 17 00:00:00 2001 From: acrovato <a.crovato@uliege.be> Date: Wed, 8 Jun 2022 15:21:10 +0200 Subject: [PATCH] Add compile before exec to get clean backtrace --- fwk/wutils.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/fwk/wutils.py b/fwk/wutils.py index 6bd7f0c..ba1c3a8 100644 --- a/fwk/wutils.py +++ b/fwk/wutils.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- # Copyright 2020 University of Liège -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -96,7 +96,7 @@ def findbins(modname, dirB=['build','wavesB'], verb=False): # changer wavesB en print("[findbins] looking for linux/mingw libs") libpath.append( os.path.join(spath, 'bin') ) # also for win-mingw - # check the paths one by one + # check the paths one by one for p in libpath: if os.path.isdir(p): if verb: @@ -156,12 +156,12 @@ def initMKL(verb=False): # Display variables if verb: for s in ['OMP', 'MKL', 'KMP']: - print('* %s environment:' % s) + print('* %s environment:' % s) for key, value in os.environ.items(): if s in key: print(' %s = %s' % (key, value)) print('') - + # ------------------------------------------------------------------------------ def setupwdir(testname): @@ -183,7 +183,7 @@ def setupwdir(testname): name = "noname" import os, os.path - # builds the name of the workspace folder + # builds the name of the workspace folder #print "__file__=",__file__ dir1 = os.path.abspath(os.path.dirname(__file__)+os.sep+"..")+os.sep print("dir1=",dir1) @@ -193,7 +193,7 @@ def setupwdir(testname): resdir = testname[len(common):].replace(os.sep,"_") resdir = os.path.splitext(resdir)[0] # remove ".py" if siz>1: - # append the mpi size if mpi is used + # append the mpi size if mpi is used # (so that the same test can be run concurrently with # sevral mpi sizes in ctest) resdir += "_mpi%d" % siz @@ -215,10 +215,10 @@ def setupwdir(testname): os.remove(fpth) elif os.path.isdir(fpth): shutil.rmtree(fpth) - + if siz>1: # if multiple process => send sync to slaves. comm.Barrier() - + # we can now safely go into the new folder os.chdir(wdir) @@ -300,4 +300,5 @@ def run(): print("starting test", testname) print("time:", time.strftime("%c")) print("hostname:", socket.gethostname()) - exec(open(testname, 'r', encoding='utf8').read(), globals(), globals()) # exec at global level!! + script = open(testname, 'r', encoding='utf-8').read() + exec(compile(script, testname, 'exec'), {'__file__': testname, '__name__':'__main__'}) # compile to get clean backtrace -- GitLab