Skip to content

Commit a11e846

Browse files
committed
Add interrupt_main() to thread module.
1 parent efad588 commit a11e846

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎Modules/threadmodule.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,21 @@ PyDoc_STRVAR(exit_doc,
278278
This is synonymous to ``raise SystemExit''. It will cause the current\n\
279279
thread to exit silently unless the exception is caught.");
280280

281+
static PyObject *
282+
sys_interrupt_main(PyObject * self, PyObject * args)
283+
{
284+
PyErr_SetInterrupt();
285+
Py_INCREF(Py_None);
286+
return Py_None;
287+
}
288+
289+
PyDoc_STRVAR(interrupt_doc,
290+
"interrupt_main()\n\
291+
\n\
292+
Raise a KeyboardInterrupt in the main thread.\n\
293+
A subthread can use this method to interrupt the main thread."
294+
);
295+
281296
#ifndef NO_EXIT_PROG
282297
static PyObject *
283298
thread_PyThread_exit_prog(PyObject *self, PyObject *args)
@@ -340,6 +355,8 @@ static PyMethodDef thread_methods[] = {
340355
METH_NOARGS, exit_doc},
341356
{"exit", (PyCFunction)thread_PyThread_exit_thread,
342357
METH_NOARGS, exit_doc},
358+
{"interrupt_main", (PyCFunction)sys_interrupt_main,
359+
METH_NOARGS, interrupt_doc},
343360
{"get_ident", (PyCFunction)thread_get_ident,
344361
METH_NOARGS, get_ident_doc},
345362
#ifndef NO_EXIT_PROG

0 commit comments

Comments
 (0)