Class PythonNetManager
Singleton manager for the PythonNet runtime lifecycle.
Must be initialized once at application startup before any prediction
blocks attempt to acquire the GIL. Call Shutdown() on
application exit to allow PythonEngine.Shutdown() to run cleanly.
Thread-safe: GIL acquisition is the caller's responsibility per-call.
Inheritance
PythonNetManager
Assembly: MOSAIC.dll
Syntax
public sealed class PythonNetManager : IDisposable
Constructors
PythonNetManager(string)
Declaration
private PythonNetManager(string configPath)
Parameters
| Type |
Name |
Description |
| string |
configPath |
|
Fields
DeployedConfigFolder
Folder a Python config is deployed to beside the executable.
Declaration
public const string DeployedConfigFolder = "Python"
Field Value
_disposed
Declaration
Field Value
_instance
Declaration
private static PythonNetManager? _instance
Field Value
_lock
Declaration
private static readonly object _lock
Field Value
_threadState
Declaration
private nint _threadState
Field Value
Properties
ConfigPath
Config file the live runtime was built from. Used to explain a second, conflicting request.
Declaration
public string ConfigPath { get; private set; }
Property Value
Instance
Declaration
public static PythonNetManager Instance { get; }
Property Value
PythonDllPath
Declaration
public string PythonDllPath { get; private set; }
Property Value
ScriptsPath
Declaration
public string ScriptsPath { get; private set; }
Property Value
SitePackagesPath
Declaration
public string SitePackagesPath { get; private set; }
Property Value
Methods
AssertReady()
Declaration
public void AssertReady()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
Initialize(string)
Initializes the Python runtime from the given config file path.
Safe to call only once; subsequent calls are no-ops if already initialized.
Declaration
public static PythonNetManager Initialize(string configPath)
Parameters
| Type |
Name |
Description |
| string |
configPath |
|
Returns
Resolve(string, string?)
Call from each prediction block's constructor or Init() to confirm
the runtime is live. Throws if manager was never initialized.
Declaration
private static string Resolve(string configDir, string? value)
Parameters
| Type |
Name |
Description |
| string |
configDir |
Folder holding the config file.
|
| string |
value |
Raw value from the config. May be absolute, relative, or empty.
|
Returns
| Type |
Description |
| string |
An absolute path.
|
ResolveConfigPath(string)
Locates a Python config file, looking beside the executable before the source tree.
Declaration
public static string ResolveConfigPath(string fileName)
Parameters
| Type |
Name |
Description |
| string |
fileName |
Config file name, e.g. config.json or configWulpus.json.
|
Returns
| Type |
Description |
| string |
Absolute path to the config file.
|
Exceptions
RunWithGIL(Action<dynamic>)
Convenience wrapper: runs action under the GIL.
Prefer this over raw Py.GIL() in block code to keep GIL usage central.
Declaration
public void RunWithGIL(Action<dynamic> action)
Parameters
Shutdown()
Shuts down the Python runtime cleanly. Call once on application exit,
e.g. from App.OnExit() or a hosted service StopAsync().
Declaration
Implements