diff --git a/DAS/simulator.py b/DAS/simulator.py index dbd1b37..8b79e2c 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -104,11 +104,12 @@ class Simulator: def initLogger(self): """It initializes the logger.""" logger = logging.getLogger("DAS") - logger.setLevel(self.logLevel) - ch = logging.StreamHandler() - ch.setLevel(self.logLevel) - ch.setFormatter(CustomFormatter()) - logger.addHandler(ch) + if len(logger.handlers) == 0: + logger.setLevel(self.logLevel) + ch = logging.StreamHandler() + ch.setLevel(self.logLevel) + ch.setFormatter(CustomFormatter()) + logger.addHandler(ch) self.logger = logger diff --git a/study.py b/study.py index 4cd4b53..914acfe 100644 --- a/study.py +++ b/study.py @@ -8,11 +8,15 @@ from DAS import * # Parallel execution: # The code currently uses 'joblib' to execute on multiple cores. For other options such as 'ray', see # https://stackoverflow.com/questions/9786102/how-do-i-parallelize-a-simple-python-loop +# For fixing logging issues in parallel execution, see +# https://stackoverflow.com/questions/58026381/logging-nested-functions-using-joblib-parallel-and-delayed-calls +# and https://github.com/joblib/joblib/issues/1017 def runOnce(sim, config, shape): if not config.deterministic: random.seed(datetime.now()) + sim.initLogger() sim.resetShape(shape) sim.initValidators() sim.initNetwork()