-
Notifications
You must be signed in to change notification settings - Fork 770
Closed
Description
Hi,
I'm using python.net in C# app and mainly calling python from worker threads. However it always hangs when trying to acquirelock from different thread than thread that did first initialization.
I'm not familiar with exact workflow with GIL, but for me, adding BeginAllowThreads() and EndAllowThreads() to GILState class helped, but I'm not sure it is proper solution.
public class GILState : IDisposable
{
private IntPtr state;
private IntPtr thread_state;
internal GILState()
{
thread_state = PythonEngine.BeginAllowThreads();
state = PythonEngine.AcquireLock();
}
public void Dispose()
{
PythonEngine.ReleaseLock(state);
GC.SuppressFinalize(this);
PythonEngine.EndAllowThreads(thread_state);
}
~GILState()
{
Dispose();
}
}Metadata
Metadata
Assignees
Labels
No labels