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

Allow GIL state debugging; require GILState to be properly disposed#1397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lostmsu merged 1 commit intopythonnet:masterfromlosttech:GIL-Threading
Mar 10, 2021
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletionssrc/runtime/pythonengine.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;

namespace Python.Runtime
{
Expand DownExpand Up@@ -51,6 +52,9 @@ public static bool IsInitialized
get { return initialized; }
}

/// <summary>Set to <c>true</c> to enable GIL debugging assistance.</summary>
public static bool DebugGIL { get; set; } = false;

internal static DelegateManager DelegateManager
{
get
Expand DownExpand Up@@ -668,7 +672,7 @@ public static GILState GIL()
PythonEngine.Initialize();
}

return new GILState();
returnPythonEngine.DebugGIL ? new DebugGILState() :new GILState();
}

public static PyScope CreateScope()
Expand All@@ -693,7 +697,7 @@ internal GILState()
state = PythonEngine.AcquireLock();
}

public void Dispose()
publicvirtualvoid Dispose()
{
if (this.isDisposed) return;

Expand All@@ -704,7 +708,23 @@ public void Dispose()

~GILState()
{
Dispose();
throw new InvalidOperationException("GIL must always be released, and it must be released from the same thread that acquired it.");
}
}

public class DebugGILState : GILState
{
readonly Thread owner;
internal DebugGILState() : base()
{
this.owner = Thread.CurrentThread;
}
public override void Dispose()
{
if (this.owner != Thread.CurrentThread)
throw new InvalidOperationException("GIL must always be released from the same thread, that acquired it");

base.Dispose();
}
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp