Skip to content

Conversation

@bakpaul
Copy link
Contributor

@bakpaul bakpaul commented Jul 12, 2024

This pr aims at fixing the crash on exit for some python scene. It was due to the cache of the Sofa python module not being cleaned up correctly (deleted after the interpreter). This is corrected here by insuring that the interpreter is correcty released through cleanup callback (see the SofaPython3 pr for more insights)


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@bakpaul bakpaul added pr: status to review To notify reviewers to review this pull-request pr: clean Cleaning the code labels Jul 12, 2024
@sofabot
Copy link
Collaborator

sofabot commented Jul 12, 2024

[ci-depends-on] detected during build #1.

To unlock the merge button, you must

@bakpaul
Copy link
Contributor Author

bakpaul commented Jul 12, 2024

[ci-build][with-all-tests]

@sofabot
Copy link
Collaborator

sofabot commented Jul 12, 2024

[ci-depends-on] detected during build #2.

To unlock the merge button, you must

@sofabot
Copy link
Collaborator

sofabot commented Jul 15, 2024

[ci-depends-on] detected during build #3.

To unlock the merge button, you must

@alxbilger alxbilger changed the title [Helper + runSofa] Added cleanup callback [Helper] Added cleanup callback Jul 15, 2024
@sofabot
Copy link
Collaborator

sofabot commented Jul 15, 2024

[ci-depends-on] detected during build #4.

To unlock the merge button, you must

@hugtalbot hugtalbot requested a review from alxbilger July 15, 2024 14:54
if (!s_cleanedUp)
{

system::PluginManager::getInstance().cleanup();
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if Sofa.Helper is the right place to call a plugin clean up...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was asked by @fredroy and it makes sens because the plugin manager belongs to Sofa.Helper

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but your goal is to clean up plugins, not the plugin manager. For example, you will clean up SofaPython3 inside the Sofa.Helper cleanup function. I am not saying it is not the right thing to do, I am just questioning ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My first though was to put it at the very end of the main function, both are justifiable. But I guess that conceptually, the cleanup order shouldn't matter, the simulation is over, we are just cleaning after us...

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not inside the destructor of PluginManager ? (if it is ever called 🥴)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want it to be in a static instance, this fix aims at cleaning the static cache before the dynamically allocated python interpreter... So no, it is necessary to have it explicitly called.

@fredroy fredroy force-pushed the fix_python_crash_on_exit branch from 79e641d to 4d74bf7 Compare July 17, 2024 05:49
@sofabot
Copy link
Collaborator

sofabot commented Jul 17, 2024

[ci-depends-on] detected during build #5.

To unlock the merge button, you must

@bakpaul
Copy link
Contributor Author

bakpaul commented Jul 17, 2024

@damienmarchal , discussions during the SOFA-dev meeting lead to a question over the developed design and your opinion is needed.

The problem was that some scenes tests where crashing at exit. This is due to the SofaPython3 cache (s_objectcache there https://github.com/sofa-framework/SofaPython3/blob/1b5d271aa21df06c4c5ab75599e364adb0c1e9be/Plugin/src/SofaPython3/DataHelper.cpp#L252C1-L252C73) . The problem was that this is a static object containing python objects and is thus cleaned at the very end of the program exit, after the python interpreter, which is not authorized.

To fix it, following pybind11 suggestions I've added a member to the module Sofa.Core that insured that the cleanup is called while the interpreter is still alive (see the PR sofa-framework/SofaPython3#425). But is was not enough because the interpreter is not cleaned correctly either : the static method "Release" of SofaPython3, in charge of cleaning up python and deleting the interpreter was never called when launching scene in runSofa.

This lead to the need of cleaning up explicitly the plugin before exiting the main function. This design was not liked by every dev, some wanting a Raii-like cleanup, in the destructor of some member, which is in my mind not possible because the interpreter instance is static in the SofaPython3 plugin and thus we have no guaranty that it would not be deleted before any other static member.

@sofabot
Copy link
Collaborator

sofabot commented Jul 18, 2024

[ci-depends-on] detected during build #6.

To unlock the merge button, you must

@bakpaul
Copy link
Contributor Author

bakpaul commented Jul 19, 2024

[ci-build][with-all-tests]

@sofabot
Copy link
Collaborator

sofabot commented Jul 19, 2024

[ci-depends-on] detected during build #6.

To unlock the merge button, you must

@fredroy fredroy force-pushed the fix_python_crash_on_exit branch from 4d74bf7 to 2870d8d Compare July 22, 2024 01:01
@sofabot
Copy link
Collaborator

sofabot commented Jul 22, 2024

[ci-depends-on] detected during build #7.

To unlock the merge button, you must

@sofa-framework sofa-framework deleted a comment from sofabot Jul 22, 2024
@fredroy fredroy force-pushed the fix_python_crash_on_exit branch from 2870d8d to de0dd56 Compare July 23, 2024 05:47
@sofabot
Copy link
Collaborator

sofabot commented Jul 23, 2024

[ci-depends-on] detected during build #9.

To unlock the merge button, you must

@hugtalbot hugtalbot changed the title [Helper] Added cleanup callback [Helper] Added cleanup callback Jul 24, 2024
@sofabot
Copy link
Collaborator

sofabot commented Aug 12, 2024

[ci-depends-on] detected during build #10.

To unlock the merge button, you must

@fredroy fredroy added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Aug 21, 2024
@sofabot
Copy link
Collaborator

sofabot commented Aug 21, 2024

[ci-depends-on] detected during build #11.

To unlock the merge button, you must

@bakpaul
Copy link
Contributor Author

bakpaul commented Aug 21, 2024

[ci-build][with-all-tests][force-full-build]

@fredroy fredroy merged commit a86e135 into sofa-framework:master Aug 21, 2024
@hugtalbot hugtalbot added this to the v24.12 milestone Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: clean Cleaning the code pr: status ready Approved a pull-request, ready to be squashed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants