Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7765474

Browse files
rmadsen-ksfilmor
authored andcommitted
Fixed #449, by added initSigs as an optional parameter to PythonEngine.Initialize.
1 parent 5c9f035 commit 7765474

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/runtime/pythonengine.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ public static void Initialize()
140140
Initialize(setSysArgv: true);
141141
}
142142

143-
public static void Initialize(bool setSysArgv = true)
143+
public static void Initialize(bool setSysArgv = true, bool initSigs = false)
144144
{
145-
Initialize(Enumerable.Empty<string>(), setSysArgv: setSysArgv);
145+
Initialize(Enumerable.Empty<string>(), setSysArgv: setSysArgv, initSigs: initSigs);
146146
}
147147

148148
/// <summary>
@@ -153,8 +153,9 @@ public static void Initialize(bool setSysArgv = true)
153153
/// more than once, though initialization will only happen on the
154154
/// first call. It is *not* necessary to hold the Python global
155155
/// interpreter lock (GIL) to call this method.
156+
/// initSigs can be set to 1 to do default python signal configuration. This will override the way signals are handled by the application.
156157
/// </remarks>
157-
public static void Initialize(IEnumerable<string> args, bool setSysArgv = true)
158+
public static void Initialize(IEnumerable<string> args, bool setSysArgv = true, bool initSigs = false)
158159
{
159160
if (!initialized)
160161
{
@@ -164,7 +165,7 @@ public static void Initialize(IEnumerable<string> args, bool setSysArgv = true)
164165
// during an initial "import clr", and the world ends shortly thereafter.
165166
// This is probably masking some bad mojo happening somewhere in Runtime.Initialize().
166167
delegateManager = new DelegateManager();
167-
Runtime.Initialize();
168+
Runtime.Initialize(initSigs);
168169
initialized = true;
169170
Exceptions.Clear();
170171

src/runtime/runtime.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ public enum MachineType
269269
/// <summary>
270270
/// Initialize the runtime...
271271
/// </summary>
272-
internal static void Initialize()
272+
internal static void Initialize(bool initSigs)
273273
{
274274
if (Py_IsInitialized() == 0)
275275
{
276-
Py_Initialize();
276+
Py_InitializeEx(initSigs ? 1 : 0);
277277
}
278278

279279
if (PyEval_ThreadsInitialized() == 0)
@@ -727,6 +727,9 @@ internal static unsafe long Refcount(IntPtr op)
727727
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
728728
internal static extern void Py_Initialize();
729729

730+
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
731+
internal static extern void Py_InitializeEx(int initsigs);
732+
730733
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
731734
internal static extern int Py_IsInitialized();
732735

0 commit comments

Comments
 (0)