pyopensn.context.Finalize
- pyopensn.context.Finalize() None
Finalize OpenSn context.
This function can only be invoked once at the end of the runtime process.
In standard Python module mode, the context is automatically finalized when the interpreter ends the lifecycle of variables. However, in environments like IPython within Jupyter, functions registered with atexit may not be executed.
In such cases, users must explicitly call this finalize function followed by MPI Finalize to properly terminate the context; otherwise, an MPI error will occur. This process can be registered to the
post_execute
event of IPython console as follows:from IPython import get_ipython def finalize_env(): Finalize() MPI.Finalize() ipython_instance = get_ipython() if ipython_instance is not None: ipython_instance.events.register("post_execute", finalize_env)
This approach allows the module to safely execute the Python script generated by
nbconvert
.