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

Remove suggestions to useinternal functions#2092

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
filmor merged 2 commits intomasterfromdrop-internal-methods-from-docs
Jan 29, 2023
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
39 changes: 25 additions & 14 deletionsdoc/source/dotnet.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,28 +42,39 @@ application.

Before interacting with any of the objects or APIs provided by the
``Python.Runtime`` namespace, calling code must have acquired the Python
global interpreter lock by calling the ``PythonEngine.AcquireLock``
method. The only exception to this rule is the
``PythonEngine.Initialize`` method, which may be called at startup
without having acquired the GIL.

When finished using Python APIs, managed code must call a corresponding
``PythonEngine.ReleaseLock`` to release the GIL and allow other threads
to use Python.
Comment on lines -50 to -52
Copy link
Member

@lostmsulostmsuJan 26, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

IMHO, "when finished" section needs corresponding replacement (maybe merged with the acquisition part).

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Better?

lostmsu reacted with thumbs up emoji

A ``using`` statement may be used to acquire and release the GIL:
global interpreter lock by ``using'' ``Py.GIL()``. The only exception to
this rule is the ``PythonEngine.Initialize`` method, which may be called
at startup without having acquired the GIL. The GIL is released again
by disposing the return value of `Py.GIL()`:

.. code:: csharp

using (Py.GIL())
{
PythonEngine.Exec("doStuff()");
}

// or
{
using var _ = Py.GIL()
PythonEngine.Exec("doStuff()");
}

// or
var gil = Py.GIL();
try
{
PythonEngine.Exec("doStuff()");
}
finally
{
gil.Dispose();
}

TheAcquireLock and ReleaseLock methods arethinwrappers over the
unmanaged``PyGILState_Ensure`` and ``PyGILState_Release``functions
from the Python API, and the documentation for those APIs applies to the
managed versions.
The``Py.GIL()'' object is athinwrapper over the unmanaged
``PyGILState_Ensure``(on construction)and ``PyGILState_Release``(on
disposal) functionsfrom the Python API, and the documentation for those
APIs applies to themanaged versions.

Passing C# Objects to the Python Engine
---------------------------------------
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp