@@ -1544,33 +1544,8 @@ signal_add_constants(PyObject *module)
1544
1544
1545
1545
1546
1546
static int
1547
- signal_module_exec (PyObject * m )
1547
+ signal_get_set_handlers (PyObject * mod_dict )
1548
1548
{
1549
- assert (!PyErr_Occurred ());
1550
-
1551
- if (signal_add_constants (m ) < 0 ) {
1552
- return -1 ;
1553
- }
1554
-
1555
- /* Add some symbolic constants to the module */
1556
- PyObject * d = PyModule_GetDict (m );
1557
- if (PyDict_SetItemString (d , "SIG_DFL" , DefaultHandler ) < 0 ) {
1558
- return -1 ;
1559
- }
1560
- if (PyDict_SetItemString (d , "SIG_IGN" , IgnoreHandler ) < 0 ) {
1561
- return -1 ;
1562
- }
1563
- #if defined(HAVE_GETITIMER ) || defined(HAVE_SETITIMER )
1564
- if (PyDict_SetItemString (d , "ItimerError" , ItimerError ) < 0 ) {
1565
- return -1 ;
1566
- }
1567
- #endif
1568
- #if defined(HAVE_SIGWAITINFO ) || defined(HAVE_SIGTIMEDWAIT )
1569
- if (PyModule_AddType (m , & SiginfoType ) < 0 ) {
1570
- return -1 ;
1571
- }
1572
- #endif
1573
-
1574
1549
// Get signal handlers
1575
1550
for (int signum = 1 ; signum < NSIG ; signum ++ ) {
1576
1551
void (* c_handler )(int ) = PyOS_getsig (signum );
@@ -1594,7 +1569,8 @@ signal_module_exec(PyObject *m)
1594
1569
// Instal Python SIGINT handler which raises KeyboardInterrupt
1595
1570
PyObject * sigint_func = get_handler (SIGINT );
1596
1571
if (sigint_func == DefaultHandler ) {
1597
- PyObject * int_handler = PyMapping_GetItemString (d , "default_int_handler" );
1572
+ PyObject * int_handler = PyMapping_GetItemString (mod_dict ,
1573
+ "default_int_handler" );
1598
1574
if (!int_handler ) {
1599
1575
return -1 ;
1600
1576
}
@@ -1603,6 +1579,44 @@ signal_module_exec(PyObject *m)
1603
1579
Py_DECREF (sigint_func );
1604
1580
PyOS_setsig (SIGINT , signal_handler );
1605
1581
}
1582
+ return 0 ;
1583
+ }
1584
+
1585
+
1586
+ static int
1587
+ signal_module_exec (PyObject * m )
1588
+ {
1589
+ assert (!PyErr_Occurred ());
1590
+
1591
+ if (signal_add_constants (m ) < 0 ) {
1592
+ return -1 ;
1593
+ }
1594
+
1595
+ /* Add some symbolic constants to the module */
1596
+ PyObject * d = PyModule_GetDict (m );
1597
+ if (PyDict_SetItemString (d , "SIG_DFL" , DefaultHandler ) < 0 ) {
1598
+ return -1 ;
1599
+ }
1600
+ if (PyDict_SetItemString (d , "SIG_IGN" , IgnoreHandler ) < 0 ) {
1601
+ return -1 ;
1602
+ }
1603
+ #if defined(HAVE_GETITIMER ) || defined(HAVE_SETITIMER )
1604
+ if (PyDict_SetItemString (d , "ItimerError" , ItimerError ) < 0 ) {
1605
+ return -1 ;
1606
+ }
1607
+ #endif
1608
+ #if defined(HAVE_SIGWAITINFO ) || defined(HAVE_SIGTIMEDWAIT )
1609
+ if (PyModule_AddType (m , & SiginfoType ) < 0 ) {
1610
+ return -1 ;
1611
+ }
1612
+ #endif
1613
+
1614
+ PyThreadState * tstate = _PyThreadState_GET ();
1615
+ if (_Py_IsMainInterpreter (tstate -> interp )) {
1616
+ if (signal_get_set_handlers (d ) < 0 ) {
1617
+ return -1 ;
1618
+ }
1619
+ }
1606
1620
1607
1621
assert (!PyErr_Occurred ());
1608
1622
return 0 ;
0 commit comments