fix issues with logging in parallel execution

For fixing logging issues see
https://stackoverflow.com/questions/58026381/logging-nested-functions-using-joblib-parallel-and-delayed-calls
and https://github.com/joblib/joblib/issues/1017

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-03-03 11:26:00 +01:00
parent f5ffb0a07b
commit 16b670e916
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
2 changed files with 10 additions and 5 deletions

View File

@ -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

View File

@ -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()