C# Class Python.Runtime.PythonEngine

This class provides the public interface of the Python runtime.
ファイルを表示 Open project: pythonnet/pythonnet Class Usage Examples

Private Properties

Property Type Description

Public Methods

Method 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 method

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
return System.IntPtr

BeginAllowThreads() public static method

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
return System.IntPtr

EndAllowThreads() public static method

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
return void

ImportModule() public static method

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
return PyObject

InitExt() public static method

public static InitExt ( ) : IntPtr
return System.IntPtr

InitExt() public static method

public static InitExt ( ) : void
return void

Initialize() public static method

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
return void

ModuleFromString() public static method

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
return PyObject

ReleaseLock() public static method

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
return void

ReloadModule() public static method

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

RunSimpleString() public static method

public static RunSimpleString ( string code ) : int
code string
return int

RunString() public static method

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
return PyObject

RunString() public static method

public static RunString ( string code, IntPtr globals, IntPtr locals ) : PyObject
code string
globals System.IntPtr
locals System.IntPtr
return PyObject

Shutdown() public static method

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
return void