Python crashes when calling sys.exit()
Python crashes when calling sys.exit() if pyluxcore.Init() was called with an call back. This is due to pyluxcore keeping a reference to the callback in a static boost::python::object. Everything works fine if python code exit normally without calling sys.exit().
I haven't yet found a work around to this problem.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
I have added a new SetLogHandler() function to the LuxCore API so it is now possible a workaround:
try:
pyluxcore.Init(loghandler.LuxCoreLogHandler)
cmd.main()
finally:
pyluxcore.SetLogHandler(None)
Calling "pyluxcore.SetLogHandler(None)" before the end fix the problem.
So the destructor of the static object attempts to clean up but the interpreter's gone?
There's atexit in Python (similar to std::atexit in C++) that lets you register a callback that is invoked before the interpreter dies. That might do to perform a safe tear-down...
Yes there is a static object holding the reference to a python object (i.e. a function call back to print log messages) and when the destructor of the static object is called, the python interpreter as already gone.
It can be solved with the try/finally or with the atexit but both solutions are not transparent for the API user: they must be coded in the application.
Yes, I meant doing the python atexit call programmatically from within C++ code, actually.
Another solution would be to have everything, including the system context in classes, then it would get destroyed when the interpreter shuts down and the cleanup could happen there.