- Notifications
You must be signed in to change notification settings - Fork749
Open
Labels
Description
importsignal
seems to break C# CTRL+C signal handling.
Environment
- Pythonnet version:
- Python version: 3.11
- Operating System: Windows 11
- .NET Runtime: 478
Details
I want to shut down the process by calling CTRL+C. That signal is intercepted from C# to call some additional logic.
However, it seems like after importing the signal module, the signal handler no longer works.
I was able to reproduce the issue modifying only the Pythonnet Console project the following way:
The following works:
// Main() ...string[]cmd=Environment.GetCommandLineArgs();PythonEngine.Initialize(false,false);Py.Import("os");// note, here the 'os' module is imported.Console.WriteLine("Waiting 5 sec. Verify if CTRL+C exits the application");System.Threading.Thread.Sleep(5000);inti=0;// int i = Runtime.Py_Main(cmd.Length, cmd);PythonEngine.Shutdown();returni;
The following does not work:
// Main() ...string[]cmd=Environment.GetCommandLineArgs();PythonEngine.Initialize();Py.Import("signal");//here the signal module gets imported.Console.WriteLine("Waiting 5 sec. Verify if CTRL+C exits the application");System.Threading.Thread.Sleep(5000);inti=0;// int i = Runtime.Py_Main(cmd.Length, cmd);PythonEngine.Shutdown();returni;
This might be the same as:#1746
Except I have not been able to reproduce the issue with numpy.
This seems like something that if it cannot be fixed, at least it should be documented how to work around it.
This also sounds a bit like#449, but that is a different issue.