-
Notifications
You must be signed in to change notification settings - Fork 203
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
MAYA-113821 MayaUSD : Python bindings un-registration of registered t… #1709
Conversation
@@ -51,12 +51,15 @@ TF_INSTANTIATE_SINGLETON(UsdMayaExportChaserRegistry); | |||
|
|||
std::map<std::string, UsdMayaExportChaserRegistry::FactoryFn> _factoryRegistry; | |||
|
|||
bool UsdMayaExportChaserRegistry::RegisterFactory(const std::string& name, FactoryFn fn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same parameter fromPython added at every Registration to determine if registration is done in c++ (within a .dll) or from Python.
if (fromPython) { | ||
g_pythonUnloaders.emplace_back(func); | ||
if (boost::python::import("atexit") | ||
.attr("register")(&PythonUnload, g_pythonUnloaders.size() - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic is here, registering to atexit with static c++ function and g_pythonUnloaders current last element.
Fixes unregistering all Python entries before the interpreter gets destroyed. The atexit logic should make sure all items registered while Python was live will be run before the interpreter exits, but I wonder if registering for onMayaExit MMessage would be safer. One interesting question is how does this work if someone unloads the mayaUsdPlugin after an export, then reloads it. Will the callback be correctly unregistered when the module is unloaded, and will they correctly be re-registered when the plugin is reloaded? Is this a case where we should prevent unloading the plugin to preserve the sanity of the registries? |
Seems like having any entry in the registries should disallow unloading the maya plugin. To test:
|
This was testing the registration/un-registration of c++ plugin not python. Right? If so, I can create a new JIRA for it and adding that the Python registration/un-registration should also be validated. As for using onMayaExit MMessage, atexit callback will be called before, which is what I prefer. What do you mean by safer? |
Yes, that test script was for the existing C++ part which is currently broken. The solution will have to be good enough to support Python as well. I have re-read how atexit works in Python and it is exactly the right function to use. Please disregard the mayaExit comment. |
Logged as MAYA-113849 Failing export after unloading/re-loading mayaUsdPlugin (https://jira.autodesk.com/browse/MAYA-113849) |
…ranslators
Register python to atexit, similar to how it is done for dlls.