Skip to content
Prev Previous commit
Next Next commit
Fixed #449, by added initSigs as an optional parameter to PythonEngin…
…e.Initialize.
  • Loading branch information
rmadsen-ks committed Apr 5, 2017
commit 8c080881a06d69599062848c57a2a74341caf98b
9 changes: 5 additions & 4 deletions src/runtime/pythonengine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ public static void Initialize()
Initialize(setSysArgv: true);
}

public static void Initialize(bool setSysArgv = true)
public static void Initialize(bool setSysArgv = true, bool initSigs = false)
{
Initialize(Enumerable.Empty<string>(), setSysArgv: setSysArgv);
Initialize(Enumerable.Empty<string>(), setSysArgv: setSysArgv, initSigs: initSigs);
}

/// <summary>
Expand All @@ -153,8 +153,9 @@ public static void Initialize(bool setSysArgv = true)
/// 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.
/// initSigs can be set to 1 to do default python signal configuration. This will override the way signals are handled by the application.
/// </remarks>
public static void Initialize(IEnumerable<string> args, bool setSysArgv = true)
public static void Initialize(IEnumerable<string> args, bool setSysArgv = true, bool initSigs = false)
{
if (!initialized)
{
Expand All @@ -164,7 +165,7 @@ public static void Initialize(IEnumerable<string> args, bool setSysArgv = true)
// during an initial "import clr", and the world ends shortly thereafter.
// This is probably masking some bad mojo happening somewhere in Runtime.Initialize().
delegateManager = new DelegateManager();
Runtime.Initialize();
Runtime.Initialize(initSigs);
initialized = true;
Exceptions.Clear();

Expand Down
7 changes: 5 additions & 2 deletions src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ public class Runtime
/// <summary>
/// Initialize the runtime...
/// </summary>
internal static void Initialize()
internal static void Initialize(bool initSigs)
{
if (Py_IsInitialized() == 0)
{
Py_Initialize();
Py_InitializeEx(initSigs ? 1 : 0);
}

if (PyEval_ThreadsInitialized() == 0)
Expand Down Expand Up @@ -584,6 +584,9 @@ internal static unsafe long Refcount(IntPtr op)
[DllImport(PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void Py_Initialize();

[DllImport(PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void Py_InitializeEx(int initsigs);

[DllImport(PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int Py_IsInitialized();

Expand Down