Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix finalizer dependency on global experiment_runner #346

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ In the 2.5.0 release of the EMAworkbench we introduce a new experimental MPIeval
Furthermore, the pair plots for scenario discovery now allow contour plots and bivariate histograms (#288). When doing Prim you can inspect multiple boxed and display them in a single figure (#317).

### Breaking changes
From 3.0 onwards, the names of parameters, constants, constraints, and outcomes must be valid python identifiers. From this version onwards, a DeprecationWarning is raised if the name is not a valid Python identifier.
From 3.0 onwards, the names of parameters, constants, constraints, and outcomes must be valid python identifiers. From this version onwards, a DeprecationWarning is raised if the name is not a valid Python identifier.

### What's Changed
#### 🎉 New features added
Expand Down
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