Skip to content

Ensure Forcing Cleanup Routine on NGEN Failure (NGWPC-10147)#169

Open
idtodd wants to merge 2 commits intodevelopmentfrom
idt-ensure-python-atexit-called
Open

Ensure Forcing Cleanup Routine on NGEN Failure (NGWPC-10147)#169
idtodd wants to merge 2 commits intodevelopmentfrom
idt-ensure-python-atexit-called

Conversation

@idtodd
Copy link
Copy Markdown

@idtodd idtodd commented Apr 10, 2026

Forcing Engine handles cleanup code through a function registered with atexit.register. When NGEN encounters an error that terminates the simulation early, this cleanup is not currently run. This PR aims to address this problem.

The change is to catch the exception from run_ngen, explicitly destroy the interpreter to ensure python's atexit runs, then rethrow the exception to seg fault the program.

There are two places where this update will not fix the current behavior:

  1. A BMI terminates the program instead of passing NGEN an error. This would happen from C/C++ BMIs that call abort() or stop in FORTRAN.
  2. During the stack unwind of run_ngen, multiple destructors throw errors. This seems most likely to happen if an exception is thrown on multiple BMI Finalize() steps as the code currently calls Finalize() in the BMIs' shared_ptr deletion.

Additions

Removals

Changes

  • Changes main to destroy the python instance if run_ngen throws an exception.
  • Removes calls to InterpreterUtil::getInstance() outside main and static methods to ensure main is solely responsible for maintaining the lifetime of the interpreter.

Testing

Screenshots

Notes

Todos

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist (automated report can be put here)

Target Environment support

  • Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant