diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -519,12 +519,11 @@ class PthreadSigmaskTests(unittest.TestC # Issue #11998: The _tkinter module loads the Tcl library which creates # a thread waiting events in select(). This thread receives signals - # blocked by all other threads. We cannot test blocked signals if the - # _tkinter module is loaded. - can_test_blocked_signals = ('_tkinter' not in sys.modules) - if not can_test_blocked_signals: - print("WARNING: _tkinter is loaded, cannot test signals " - "blocked by pthread_sigmask() (issue #11998)") + # blocked by all other threads. Finalize the Tcl library to exit the + # Tcl thread. + if '_tkinter' in sys.modules: + import _tkinter + _tkinter._finalize() # Install our signal handler old_handler = signal.signal(signum, handler) @@ -539,8 +538,7 @@ class PthreadSigmaskTests(unittest.TestC # Block and then raise SIGUSR1. The signal is blocked: the signal # handler is not called, and the signal is now pending signal.pthread_sigmask(signal.SIG_BLOCK, [signum]) - if can_test_blocked_signals: - os.kill(pid, signum) + os.kill(pid, signum) # Check the new mask blocked = read_sigmask() @@ -548,11 +546,8 @@ class PthreadSigmaskTests(unittest.TestC self.assertEqual(set(old_mask) ^ set(blocked), {signum}) # Unblock SIGUSR1 - if can_test_blocked_signals: - with self.assertRaises(ZeroDivisionError): - # unblock the pending signal calls immediatly the signal handler - signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum]) - else: + with self.assertRaises(ZeroDivisionError): + # unblock the pending signal calls immediatly the signal handler signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum]) with self.assertRaises(ZeroDivisionError): os.kill(pid, signum) diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -2941,6 +2941,18 @@ static char getbusywaitinterval_doc[] = Return the current busy-wait interval between successive\n\ calls to Tcl_DoOneEvent in a threaded Python interpreter."; +static PyObject * +Tkinter_finalize(PyObject *self, PyObject *args) +{ + Tcl_Finalize(); + Py_RETURN_NONE; +} + +static char finalize_doc[] = +"_finalize()\n\ +\n\ +Finalize the Tcl library."; + static PyMethodDef moduleMethods[] = { {"_flatten", Tkinter_Flatten, METH_VARARGS}, @@ -2949,6 +2961,8 @@ static PyMethodDef moduleMethods[] = setbusywaitinterval_doc}, {"getbusywaitinterval",(PyCFunction)Tkinter_getbusywaitinterval, METH_NOARGS, getbusywaitinterval_doc}, + {"_finalize", (PyCFunction)Tkinter_finalize, + METH_NOARGS, finalize_doc}, {NULL, NULL} };