Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1e5338f

Browse files
committed
allow GIL state debugging; require GILState to be properly disposed
#1389 (comment)
1 parent4afa4bd commit1e5338f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

‎src/runtime/pythonengine.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
usingSystem.Linq;
55
usingSystem.Reflection;
66
usingSystem.Runtime.InteropServices;
7+
usingSystem.Threading;
78

89
namespacePython.Runtime
910
{
@@ -51,6 +52,9 @@ public static bool IsInitialized
5152
get{returninitialized;}
5253
}
5354

55+
/// <summary>Set to <c>true</c> to enable GIL debugging assistance.</summary>
56+
publicstaticboolDebugGIL{get;set;}=false;
57+
5458
internalstaticDelegateManagerDelegateManager
5559
{
5660
get
@@ -633,7 +637,7 @@ public static GILState GIL()
633637
PythonEngine.Initialize();
634638
}
635639

636-
returnnewGILState();
640+
returnPythonEngine.DebugGIL?newDebugGILState():newGILState();
637641
}
638642

639643
publicstaticPyScopeCreateScope()
@@ -658,7 +662,7 @@ internal GILState()
658662
state=PythonEngine.AcquireLock();
659663
}
660664

661-
publicvoidDispose()
665+
publicvirtualvoidDispose()
662666
{
663667
if(this.isDisposed)return;
664668

@@ -669,7 +673,23 @@ public void Dispose()
669673

670674
~GILState()
671675
{
672-
Dispose();
676+
thrownewInvalidOperationException("GIL must always be released, and it must be released from the same thread that acquired it.");
677+
}
678+
}
679+
680+
publicclassDebugGILState:GILState
681+
{
682+
readonlyThreadowner;
683+
internalDebugGILState():base()
684+
{
685+
this.owner=Thread.CurrentThread;
686+
}
687+
publicoverridevoidDispose()
688+
{
689+
if(this.owner!=Thread.CurrentThread)
690+
thrownewInvalidOperationException("GIL must always be released from the same thread, that acquired it");
691+
692+
base.Dispose();
673693
}
674694
}
675695

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp