Releasing GIL in long-running C# method causes "Fatal Python error: PyEval_SaveThread: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)" #2209
Replies: 2 comments 3 replies
-
When Python calls C# GIL is not held in the first place, so no need to release anything. |
Beta Was this translation helpful? Give feedback.
-
Hi @lostmsu. I'm confused by your comment:
This seems to contradict this page https://github.com/pythonnet/pythonnet/wiki/Threading which says: "If you are calling C# from Python, and the C# code performs a long-running operation (e.g. computation, I/O, sleep, acquiring a lock, ...), release the GIL via PythonEngine.BeginAllowThreads(). Remember to restore it before returning control to Python" The same question is here: #2424 |
Beta Was this translation helpful? Give feedback.
-
Environment
Details
I'm trying to prevent a long running method in C# from blocking execution in Python. I followed the guidance on https://github.com/pythonnet/pythonnet/wiki/Threading but I am getting a crash.
Minimal, Complete, and Verifiable example
this will help us understand the issue.
Beta Was this translation helpful? Give feedback.
All reactions