You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently ran into the same issue as #795. (To summarize: I obtained the GIL in .NET, executed Python code that called a .NET method that called Python. This caused a AccessViolationException exception.) That issue was closed with a "by design" comment, with no explanation as to why it is designed this way nor any reference to documentation.
Issue #2208 is similar and was also closed, with a comment saying "When Python calls C# GIL is not held in the first place".
This behavior is counter-intuitive, and documentation even seems to say that this is not expected behavior. The threading wiki page states that "If you are calling C# from Python ... release the GIL" implying that the GIL is still held when Python calls .NET. In fact, calling PythonEngine.BeginAllowThreads() as it recommends throws an exception.
I would suggest that the threading page be updated, and the README be updated to clarify this where it says "All calls to python should be inside a using (Py.GIL()) {/* Your code here */} block.".
The text was updated successfully, but these errors were encountered:
The threading wiki is a wiki, it's not official documentation. If you want to change something, change it
PRs are always welcome. It is however not quite true that all calls to Python need to be wrapped, you can use the ForbidPythonThreads attribute to enter a C# function with the GIL being held.
I recently ran into the same issue as #795. (To summarize: I obtained the GIL in .NET, executed Python code that called a .NET method that called Python. This caused a AccessViolationException exception.) That issue was closed with a "by design" comment, with no explanation as to why it is designed this way nor any reference to documentation.
Issue #2208 is similar and was also closed, with a comment saying "When Python calls C# GIL is not held in the first place".
This behavior is counter-intuitive, and documentation even seems to say that this is not expected behavior. The threading wiki page states that "If you are calling C# from Python ... release the GIL" implying that the GIL is still held when Python calls .NET. In fact, calling PythonEngine.BeginAllowThreads() as it recommends throws an exception.
I would suggest that the threading page be updated, and the README be updated to clarify this where it says "All calls to python should be inside a using (Py.GIL()) {/* Your code here */} block.".
The text was updated successfully, but these errors were encountered: