summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/interruptmodule.c
blob: 8e18d5af906d0c460491ca643bb7996741ba30c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/***********************************************************************
 *  interruptmodule.c
 *
 *  Python extension implementing the interrupt module.
 *  
 **********************************************************************/

#include "Python.h"

#ifndef PyDoc_STR
#define PyDoc_VAR(name) static char name[]
#define PyDoc_STR(str) str
#define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
#endif

/* module documentation */

PyDoc_STRVAR(module_doc,
"Provide a way to interrupt the main thread from a subthread.\n\n\
In threaded Python code the KeyboardInterrupt is always directed to\n\
the thread which raised it.  This extension provides a method,\n\
interrupt_main, which a subthread can use to raise a KeyboardInterrupt\n\
in the main thread.");

/* module functions */

static PyObject *
setinterrupt(PyObject * self, PyObject * args)
{
	PyErr_SetInterrupt();
	Py_INCREF(Py_None);
	return Py_None;
}

/* registration table */

static struct PyMethodDef methods[] = {
	{"interrupt_main", setinterrupt, METH_VARARGS,
	 PyDoc_STR("Interrupt the main thread")},
	{NULL, NULL}
};

/* module initialization */

void
initinterrupt(void)
{
	(void) Py_InitModule3("interrupt", methods, module_doc);
}