C# Class Python.Runtime.PythonEngine

This class provides the public interface of the Python runtime.
Afficher le fichier Open project: pythonnet/pythonnet Class Usage Examples

Private Properties

Свойство Type Description

Méthodes publiques

Méthode Description
AcquireLock ( ) : IntPtr

AcquireLock Method

Acquire the Python global interpreter lock (GIL). Managed code *must* call this method before using any objects or calling any methods on objects in the Python.Runtime namespace. The only exception is PythonEngine.Initialize, which may be called without first calling AcquireLock. Each call to AcquireLock must be matched by a corresponding call to ReleaseLock, passing the token obtained from AcquireLock. For more information, see the "Extending and Embedding" section of the Python documentation on www.python.org.

BeginAllowThreads ( ) : IntPtr

BeginAllowThreads Method

Release the Python global interpreter lock to allow other threads to run. This is equivalent to the Py_BEGIN_ALLOW_THREADS macro provided by the C Python API. For more information, see the "Extending and Embedding" section of the Python documentation on www.python.org.

EndAllowThreads ( IntPtr ts ) : void

EndAllowThreads Method

Re-aquire the Python global interpreter lock for the current thread. This is equivalent to the Py_END_ALLOW_THREADS macro provided by the C Python API. For more information, see the "Extending and Embedding" section of the Python documentation on www.python.org.

ImportModule ( string name ) : PyObject

ImportModule Method

Given a fully-qualified module or package name, import the module and return the resulting module object as a PyObject or null if an exception is raised.

InitExt ( ) : IntPtr
InitExt ( ) : void
Initialize ( ) : void

Initialize Method

Initialize the Python runtime. It is safe to call this method more than once, though initialization will only happen on the first call. It is *not* necessary to hold the Python global interpreter lock (GIL) to call this method.

ModuleFromString ( string name, string code ) : PyObject

ModuleFromString Method

Given a string module name and a string containing Python code, execute the code in and return a module of the given name.

ReleaseLock ( IntPtr gs ) : void

ReleaseLock Method

Release the Python global interpreter lock using a token obtained from a previous call to AcquireLock. For more information, see the "Extending and Embedding" section of the Python documentation on www.python.org.

ReloadModule ( PyObject module ) : PyObject

ReloadModule Method

Given a PyObject representing a previously loaded module, reload the module.

RunSimpleString ( string code ) : int
RunString ( string code ) : PyObject

RunString Method

Run a string containing Python code. Returns the result of executing the code string as a PyObject instance, or null if an exception was raised.

RunString ( string code, IntPtr globals, IntPtr locals ) : PyObject
Shutdown ( ) : void

Shutdown Method

Shutdown and release resources held by the Python runtime. The Python runtime can no longer be used in the current process after calling the Shutdown method.

Method Details

AcquireLock() public static méthode

AcquireLock Method
Acquire the Python global interpreter lock (GIL). Managed code *must* call this method before using any objects or calling any methods on objects in the Python.Runtime namespace. The only exception is PythonEngine.Initialize, which may be called without first calling AcquireLock. Each call to AcquireLock must be matched by a corresponding call to ReleaseLock, passing the token obtained from AcquireLock. For more information, see the "Extending and Embedding" section of the Python documentation on www.python.org.
public static AcquireLock ( ) : IntPtr
Résultat System.IntPtr

BeginAllowThreads() public static méthode

BeginAllowThreads Method
Release the Python global interpreter lock to allow other threads to run. This is equivalent to the Py_BEGIN_ALLOW_THREADS macro provided by the C Python API. For more information, see the "Extending and Embedding" section of the Python documentation on www.python.org.
public static BeginAllowThreads ( ) : IntPtr
Résultat System.IntPtr

EndAllowThreads() public static méthode

EndAllowThreads Method
Re-aquire the Python global interpreter lock for the current thread. This is equivalent to the Py_END_ALLOW_THREADS macro provided by the C Python API. For more information, see the "Extending and Embedding" section of the Python documentation on www.python.org.
public static EndAllowThreads ( IntPtr ts ) : void
ts System.IntPtr
Résultat void

ImportModule() public static méthode

ImportModule Method
Given a fully-qualified module or package name, import the module and return the resulting module object as a PyObject or null if an exception is raised.
public static ImportModule ( string name ) : PyObject
name string
Résultat PyObject

InitExt() public static méthode

public static InitExt ( ) : IntPtr
Résultat System.IntPtr

InitExt() public static méthode

public static InitExt ( ) : void
Résultat void

Initialize() public static méthode

Initialize Method
Initialize the Python runtime. It is safe to call this method more than once, though initialization will only happen on the first call. It is *not* necessary to hold the Python global interpreter lock (GIL) to call this method.
public static Initialize ( ) : void
Résultat void

ModuleFromString() public static méthode

ModuleFromString Method
Given a string module name and a string containing Python code, execute the code in and return a module of the given name.
public static ModuleFromString ( string name, string code ) : PyObject
name string
code string
Résultat PyObject

ReleaseLock() public static méthode

ReleaseLock Method
Release the Python global interpreter lock using a token obtained from a previous call to AcquireLock. For more information, see the "Extending and Embedding" section of the Python documentation on www.python.org.
public static ReleaseLock ( IntPtr gs ) : void
gs System.IntPtr
Résultat void

ReloadModule() public static méthode

ReloadModule Method
Given a PyObject representing a previously loaded module, reload the module.
public static ReloadModule ( PyObject module ) : PyObject
module PyObject
Résultat PyObject

RunSimpleString() public static méthode

public static RunSimpleString ( string code ) : int
code string
Résultat int

RunString() public static méthode

RunString Method
Run a string containing Python code. Returns the result of executing the code string as a PyObject instance, or null if an exception was raised.
public static RunString ( string code ) : PyObject
code string
Résultat PyObject

RunString() public static méthode

public static RunString ( string code, IntPtr globals, IntPtr locals ) : PyObject
code string
globals System.IntPtr
locals System.IntPtr
Résultat PyObject

Shutdown() public static méthode

Shutdown Method
Shutdown and release resources held by the Python runtime. The Python runtime can no longer be used in the current process after calling the Shutdown method.
public static Shutdown ( ) : void
Résultat void