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

[Bindings] Remove static SofaInitializer, call unload into each respective module and clear cache #432

Merged
merged 4 commits into from
Aug 29, 2024

Conversation

fredroy
Copy link
Contributor

@fredroy fredroy commented Jul 25, 2024

Was
A small experiment (successful?) about unloading module when they themselves are unloaded~~
Also should help fix the shenanigans about #425 and sofa-framework/sofa#4828

This PR:

output before:

$ python
Python 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import Sofa
---------------------------------------
Checking SOFA_ROOT and SOFAPYTHON3_ROOT
Using environment variable SOFA_ROOT: D:\sofa\build\current
Warning: environment variable SOFAPYTHON3_ROOT is empty. Trying to guess it.
Guessed SOFAPYTHON3_ROOT: D:\sofa\build\current
Detected SOFA development build
Detected SofaPython3 development build
Found Sofa.Helper.dll in D:\sofa\build\current\bin\RelWithDebInfo
Found SofaPython3.dll in D:\sofa\build\current\bin\RelWithDebInfo
---------------------------------------
>>> quit()
[WARNING] [Sofa.Simulation.Graph] the library has not been cleaned up (sofa::simulation::graph::cleanup() has never been called, see sofa/helper/init.h)
[WARNING] [SofaSimulationCommon] the library has not been cleaned up (sofa::simulation::common::cleanup() has never been called, see sofa/helper/init.h)
[WARNING] [SofaSimulationCore] the library has not been cleaned up (sofa::simulation::core::cleanup() has never been called, see sofa/helper/init.h)
[WARNING] [SofaCore] the library has not been cleaned up (sofa::core::cleanup() has never been called, see sofa/helper/init.h)
[WARNING] [SofaDefaultType] the library has not been cleaned up (sofa::defaulttype::cleanup() has never been called, see sofa/helper/init.h)
[WARNING] [SofaHelper] the library has not been cleaned up (sofa::helper::cleanup() has never been called, see sofa/helper/init.h)

output after:

$ python
Python 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import Sofa
---------------------------------------
Checking SOFA_ROOT and SOFAPYTHON3_ROOT
Using environment variable SOFA_ROOT: D:\sofa\build\current
Warning: environment variable SOFAPYTHON3_ROOT is empty. Trying to guess it.
Guessed SOFAPYTHON3_ROOT: D:\sofa\build\current
Detected SOFA development build
Detected SofaPython3 development build
Found Sofa.Helper.dll in D:\sofa\build\current\bin\RelWithDebInfo
Found SofaPython3.dll in D:\sofa\build\current\bin\RelWithDebInfo
---------------------------------------
>>> quit()
[INFO]    [SofaPython3.Simulation] Sofa.Simulation unload()
[INFO]    [SofaPython3.Core] Sofa.Core unload()
[INFO]    [SofaPython3.Helper] Sofa.Helper unload()

Thanks to https://pybind11.readthedocs.io/en/stable/advanced/misc.html#module-destructors

Copy link
Contributor

@alxbilger alxbilger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍

@fredroy fredroy force-pushed the test_nonstatic_init branch 2 times, most recently from 637c16a to c922ecb Compare August 12, 2024 02:16
@fredroy fredroy changed the title [Bindings] Remove static SofaInitializer and call unload into each respective module [Bindings] Remove static SofaInitializer, call unload into each respective module and clear cache Aug 27, 2024
@bakpaul bakpaul merged commit 4b0ce86 into sofa-framework:master Aug 29, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

import Sofa does not cleanup
3 participants