Skip to content

Commit

Permalink
Fix finalizer dependency on global experiment_runner (#346)
Browse files Browse the repository at this point in the history
* bugfix to finalizer

fixes a bug in the finalizer in case of working directory models

* Update futures_util.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and EwoutH committed Apr 17, 2024
1 parent 3900ed7 commit 4c71b68
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ema_workbench/em_framework/futures_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def mpi_initializer(models, log_level, root_dir):
# setup the working directories
tmpdir = setup_working_directories(models, root_dir)
if tmpdir:
atexit.register(finalizer, os.path.abspath(tmpdir))
atexit.register(finalizer(experiment_runner), os.path.abspath(tmpdir))

# _logger.info(f"worker {rank} initialized")
root_logger.info(f"worker {rank} initialized")
Expand Down
2 changes: 1 addition & 1 deletion ema_workbench/em_framework/futures_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def initializer(*args):
# remove the root temp
if tmpdir:
multiprocessing.util.Finalize(
None, finalizer, args=(os.path.abspath(tmpdir),), exitpriority=10
None, finalizer(experiment_runner), args=(os.path.abspath(tmpdir),), exitpriority=10
)


Expand Down
25 changes: 14 additions & 11 deletions ema_workbench/em_framework/futures_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,24 @@ def determine_rootdir(msis):
return root_dir


def finalizer(tmpdir):
def finalizer(experiment_runner):
"""cleanup"""
global experiment_runner
_logger.info("finalizing")

experiment_runner.cleanup()
del experiment_runner
def finalizer(tmpdir):
_logger.info("finalizing")

time.sleep(1)
experiment_runner.cleanup()
# del experiment_runner

if tmpdir:
try:
shutil.rmtree(tmpdir)
except OSError:
pass
time.sleep(1)

if tmpdir:
try:
shutil.rmtree(tmpdir)
except OSError:
pass

return finalizer


def setup_working_directories(models, root_dir):
Expand Down

0 comments on commit 4c71b68

Please sign in to comment.