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

Commit3362cf8

Browse files
authored
GILState.Dispose is safe to be called multiple times (#1037)
* GILState.Dispose is safe to be called multiple times* test multiple class to GILState.Dispose
1 parent3b938a5 commit3362cf8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

‎src/embed_tests/TestGILState.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespacePython.EmbeddingTest
2+
{
3+
usingNUnit.Framework;
4+
usingPython.Runtime;
5+
6+
publicclassTestGILState
7+
{
8+
/// <summary>
9+
/// Ensure, that calling <see cref="Py.GILState.Dispose"/> multiple times is safe
10+
/// </summary>
11+
[Test]
12+
publicvoidCanDisposeMultipleTimes()
13+
{
14+
using(vargilState=Py.GIL())
15+
{
16+
for(inti=0;i<50;i++)
17+
gilState.Dispose();
18+
}
19+
}
20+
}
21+
}

‎src/runtime/pythonengine.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,8 @@ public static PyScope CreateScope(string name)
643643

644644
publicclassGILState:IDisposable
645645
{
646-
privateIntPtrstate;
646+
privatereadonlyIntPtrstate;
647+
privateboolisDisposed;
647648

648649
internalGILState()
649650
{
@@ -652,8 +653,11 @@ internal GILState()
652653

653654
publicvoidDispose()
654655
{
656+
if(this.isDisposed)return;
657+
655658
PythonEngine.ReleaseLock(state);
656659
GC.SuppressFinalize(this);
660+
this.isDisposed=true;
657661
}
658662

659663
~GILState()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp