FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Remove suggestions to use `internal` functions by filmor · Pull Request #2092 · pythonnet/pythonnet · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rst  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
39 changes: 25 additions & 14 deletions doc/source/dotnet.rst
This file contains hidden or 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
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

lostmsu Jan 26, 2023
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Better?


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();
}

The AcquireLock and ReleaseLock methods are thin wrappers 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 a thin wrapper over the unmanaged
``PyGILState_Ensure`` (on construction) and ``PyGILState_Release`` (on
disposal) functions from the Python API, and the documentation for those
APIs applies to the managed versions.

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

Back | FazBrowse Home | New Git URL