X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix race in signal handling
  • Loading branch information
kumaraditya303 committed Mar 3, 2023
commit ace9cf5c167d1bf69ff37e1367f335888c6a0a2a
15 changes: 15 additions & 0 deletions Lib/test/test_signal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _thread
import enum
import errno
import inspect
Expand Down Expand Up @@ -1406,6 +1407,20 @@ def handler(a, b):
signal.raise_signal(signal.SIGINT)
self.assertTrue(is_ok)

def test__thread_interrupt_main(self):
code = """if 1:
import _thread
class Foo():
def __del__(self):
_thread.interrupt_main()

x = Foo()
"""

rc, out, err = assert_python_ok('-c', code)
self.assertIn(b'OSError: Signal 2 ignored due to race condition', err)



class PidfdSignalTest(unittest.TestCase):

Expand Down
3 changes: 3 additions & 0 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ get_signal_state(PyObject *module)
static inline int
compare_handler(PyObject *func, PyObject *dfl_ign_handler)
{
if (func == NULL || dfl_ign_handler == NULL) {
return 0;
}
assert(PyLong_CheckExact(dfl_ign_handler));
if (!PyLong_CheckExact(func)) {
return 0;
Expand Down
X Tutup