Skip to content

Crash on shutdown when embedding Python in C# #1831

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

Closed
BadSingleton opened this issue Jun 23, 2022 · 3 comments
Closed

Crash on shutdown when embedding Python in C# #1831

BadSingleton opened this issue Jun 23, 2022 · 3 comments

Comments

@BadSingleton
Copy link
Contributor

Environment

  • Pythonnet version: a80c685
  • Python version: 3.9.10
  • Operating System: Windows (probably others too)
  • .NET Runtime: mono/Unity

Details

Using the Python for Unity package with at a commit hash later or equal to the one above, pythonnet causes a crash on Shutdown. I've traced the issue to this PR: #1780 which is cause by checking a Python internal without holding the GIL; which the shutdown process isn't doing (or at least not at this point).

@BadSingleton BadSingleton changed the title Crash on when embedding Python in C# Crash on shutdown when embedding Python in C# Jun 23, 2022
@filmor
Copy link
Member

filmor commented Jun 23, 2022

Is the Exceptions.ErrorOccurred() the culprit? Does it work if that whole section is put in a using (Py.GIL) scope?

@BadSingleton
Copy link
Contributor Author

It is the culprit. I'm unsure if it is totally advisable; PR incoming; grabbing the GIL only when embedded.

@Martin-Molinero
Copy link
Contributor

Just adding to this: we are seeing a similar segmentation fault while shutting down, only while debugging for same reason. Manually shutting down seems to avoid the seg fault QuantConnect/Lean#6439

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants