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

Commitc2fa467

Browse files
authored
Remove suggestions to useinternal functions (#2092)
Fixes#2091
1 parenta041811 commitc2fa467

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

‎doc/source/dotnet.rst

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,39 @@ application.
4242

4343
Before interacting with any of the objects or APIs provided by the
4444
``Python.Runtime`` namespace, calling code must have acquired the Python
45-
global interpreter lock by calling the ``PythonEngine.AcquireLock``
46-
method. The only exception to this rule is the
47-
``PythonEngine.Initialize`` method, which may be called at startup
48-
without having acquired the GIL.
49-
50-
When finished using Python APIs, managed code must call a corresponding
51-
``PythonEngine.ReleaseLock`` to release the GIL and allow other threads
52-
to use Python.
53-
54-
A ``using`` statement may be used to acquire and release the GIL:
45+
global interpreter lock by ``using'' ``Py.GIL()``. The only exception to
46+
this rule is the ``PythonEngine.Initialize`` method, which may be called
47+
at startup without having acquired the GIL. The GIL is released again
48+
by disposing the return value of `Py.GIL()`:
5549

5650
..code::csharp
5751
5852
using (Py.GIL())
5953
{
6054
PythonEngine.Exec("doStuff()");
6155
}
56+
57+
// or
58+
{
59+
usingvar_=Py.GIL()
60+
PythonEngine.Exec("doStuff()");
61+
}
62+
63+
// or
64+
vargil=Py.GIL();
65+
try
66+
{
67+
PythonEngine.Exec("doStuff()");
68+
}
69+
finally
70+
{
71+
gil.Dispose();
72+
}
6273
63-
TheAcquireLock and ReleaseLock methods arethinwrappers over the
64-
unmanaged``PyGILState_Ensure`` and ``PyGILState_Release``functions
65-
from the Python API, and the documentation for those APIs applies to the
66-
managed versions.
74+
The``Py.GIL()'' object is athinwrapper over the unmanaged
75+
``PyGILState_Ensure``(on construction)and ``PyGILState_Release``(on
76+
disposal) functionsfrom the Python API, and the documentation for those
77+
APIs applies to themanaged versions.
6778

6879
Passing C# Objects to the Python Engine
6980
---------------------------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp