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

Python crashes when calling sys.exit() #29

Open
Dade916 opened this Issue Dec 31, 2017 · 4 comments

Comments

Projects
2 participants
@Dade916
Member

Dade916 commented Dec 31, 2017

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.

@Dade916

This comment has been minimized.

Member

Dade916 commented Jan 7, 2018

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.

@Dade916 Dade916 added this to Known problems in LuxCoreRender v2.0 Jan 7, 2018

@tschw

This comment has been minimized.

Contributor

tschw commented Mar 23, 2018

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...

@Dade916

This comment has been minimized.

Member

Dade916 commented Mar 23, 2018

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.

@tschw

This comment has been minimized.

Contributor

tschw commented Mar 23, 2018

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.

Theverat added a commit to LuxCoreRender/BlendLuxCore that referenced this issue Jul 20, 2018

Theverat added a commit to LuxCoreRender/BlendLuxCore that referenced this issue Jul 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment