blob: 8e18d5af906d0c460491ca643bb7996741ba30c1 [file] [log] [blame]
Kurt B. Kaiser98b15ab2003-03-10 20:41:07 +00001/***********************************************************************
2 * interruptmodule.c
3 *
4 * Python extension implementing the interrupt module.
5 *
6 **********************************************************************/
7
8#include "Python.h"
9
10#ifndef PyDoc_STR
11#define PyDoc_VAR(name) static char name[]
12#define PyDoc_STR(str) str
13#define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
14#endif
15
16/* module documentation */
17
18PyDoc_STRVAR(module_doc,
19"Provide a way to interrupt the main thread from a subthread.\n\n\
20In threaded Python code the KeyboardInterrupt is always directed to\n\
21the thread which raised it. This extension provides a method,\n\
22interrupt_main, which a subthread can use to raise a KeyboardInterrupt\n\
23in the main thread.");
24
25/* module functions */
26
27static PyObject *
28setinterrupt(PyObject * self, PyObject * args)
29{
30 PyErr_SetInterrupt();
31 Py_INCREF(Py_None);
32 return Py_None;
33}
34
35/* registration table */
36
37static struct PyMethodDef methods[] = {
38 {"interrupt_main", setinterrupt, METH_VARARGS,
39 PyDoc_STR("Interrupt the main thread")},
40 {NULL, NULL}
41};
42
43/* module initialization */
44
45void
46initinterrupt(void)
47{
48 (void) Py_InitModule3("interrupt", methods, module_doc);
49}