-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first attempt to add python interpreter lock. Not working
- Loading branch information
1 parent
db1ed53
commit 8e3f362
Showing
5 changed files
with
37 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Python.Runtime; | ||
using System; | ||
|
||
public sealed class GilManager | ||
{ | ||
private static readonly Lazy<GilManager> _instance = new Lazy<GilManager>(() => new GilManager()); | ||
public static GilManager Instance => _instance.Value; | ||
|
||
private GilManager() | ||
{ | ||
} | ||
|
||
public void ExecuteWithGil(Action action) | ||
{ | ||
using (Py.GIL()) // Acquire GIL | ||
{ | ||
action(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,7 @@ internal RuntimeManager(string pythonHome, string scriptPath, IObserver<RuntimeM | |
{ | ||
Initialize(pythonHome); | ||
threadState = PythonEngine.BeginAllowThreads(); | ||
using (Py.GIL()) | ||
{ | ||
MainModule = CreateModule(scriptPath: scriptPath); | ||
} | ||
MainModule = CreateModule(scriptPath: scriptPath); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ncguilbeault
Author
Contributor
|
||
observer.OnNext(this); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I think this line might be a problem. Module creation should run inside the GIL and this code is not under control from any nested operator, so I don't think we can assume that we can remove the call to
Py.GIL
here.