This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: SIGINT always reset to SIG_DFL by Py_Finalize()
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
Status: closed Resolution: duplicate
Dependencies: Superseder: signal module always overwrites SIGINT on interpreter shutdown
View: 30654
Assigned To: Nosy List: ABalmosan, martin.panter, ncoghlan, vstinner
Priority: normal Keywords:

Created on 2015-06-09 12:30 by ABalmosan, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg245060 - (view) Author: (ABalmosan) Date: 2015-06-09 12:30
We use the Python lib as part of a larger process. This process sets its own signal handlers to achieve the expected behavior of the process.

We use Py_InitializeEx(0) to prevent Python to install its own signal handlers.

On process reconfigure we shutdown Python with Py_Finalize() to call Py_InitializeEx(0) anew. 

Even so Py_InitializeEx(0) did not touch any signal and especially not SIGINT, Py_Finalize() resets unconditionally SIGINT to SIG_DFL.

The result is that our process terminates immediately on SIGINT instead of execution its shutdown procedure which was handled by the orginal installed SIGINT handler.

The problem is visible in the python code in 

static void
    int i;
    PyObject *func;

    PyOS_setsig(SIGINT, old_siginthandler);
    old_siginthandler = SIG_DFL;

In Python/pythonrun.c Py_InitializeEx()I find:

    if (install_sigs)
        initsigs(); /* Signal handling stuff, including initintr() */

Also I wonder by whom PyOS_InitInterrupts() is called. It would unconditionally install the Python signal handler even if Py_InitializeEx(0) was once executed.
msg319607 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2018-06-15 11:27
It is worth checking if at least the first half of the report was fixed by Issue 30654
msg363787 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-09 23:23
I mark this issue as a duplicate of bpo-30654. If it's not the case, please add a comment/reopen the issue.
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68603
2020-03-09 23:23:57vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg363787

resolution: duplicate
stage: resolved
2018-06-15 11:27:53martin.pantersetsuperseder: signal module always overwrites SIGINT on interpreter shutdown

messages: + msg319607
nosy: + martin.panter
2015-06-09 12:43:34r.david.murraysetnosy: + ncoghlan
2015-06-09 12:30:06ABalmosancreate