You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python relies on reference counting to clean up objects. In our case, however, the reference count for the library and mesh objects is not guaranteed to be correct, which cause some error when mesh is not manually deleted.
At the moment, I see two potential approaches to address the bug:
Correct the reference count using py::keep_alive from pybind11. This is the approach implemented in Improve MPI lifecycle management in PyOmega_h #233 . It keeps the existing code structure nearly unchanged. The concern is that keep_alive is not a particularly common approach as far as I know. Most software tends to address object lifetime issues on the C++ side rather than modifying the lifetime relationship from the Python binding side. Therefore, we are not sure what other consequences this approach might have.
Initialize the Omega_h library when importing the Python module and explicitly register its cleanup. With this approach, the lifecycle of the Omega_h library is moved outside the normal Python script objects scope. This would ensure that the library remains alive until after the mesh objects have been destroyed. The concern is that a slightly different pattern (library becomes kind of global singleton) is introduced from what we currently use on the C++ side.
I would appreciate any feedback on which approach would be more appropriate, or whether there is another solution we should consider. Some related code from other software is shown below for reference.
pykokkos bindings
PETSc initialize/finalize
Python relies on reference counting to clean up objects. In our case, however, the reference count for the library and mesh objects is not guaranteed to be correct, which cause some error when mesh is not manually deleted.
At the moment, I see two potential approaches to address the bug:
Correct the reference count using
py::keep_alivefrom pybind11. This is the approach implemented in Improve MPI lifecycle management in PyOmega_h #233 . It keeps the existing code structure nearly unchanged. The concern is thatkeep_aliveis not a particularly common approach as far as I know. Most software tends to address object lifetime issues on the C++ side rather than modifying the lifetime relationship from the Python binding side. Therefore, we are not sure what other consequences this approach might have.Initialize the Omega_h library when importing the Python module and explicitly register its cleanup. With this approach, the lifecycle of the Omega_h library is moved outside the normal Python script objects scope. This would ensure that the library remains alive until after the mesh objects have been destroyed. The concern is that a slightly different pattern (library becomes kind of global singleton) is introduced from what we currently use on the C++ side.
I would appreciate any feedback on which approach would be more appropriate, or whether there is another solution we should consider. Some related code from other software is shown below for reference.
pykokkos bindings
PETSc initialize/finalize