]> granicus.if.org Git - python/commitdiff
A interruptmodule.c
authorKurt B. Kaiser <kbk@shore.net>
Mon, 10 Mar 2003 20:41:07 +0000 (20:41 +0000)
committerKurt B. Kaiser <kbk@shore.net>
Mon, 10 Mar 2003 20:41:07 +0000 (20:41 +0000)
M setup.py
Implements an interrupt extension module which allows a subthread
to raise an interrupt in the main thread.

Lib/idlelib/interruptmodule.c [new file with mode: 0644]
Lib/idlelib/setup.py

diff --git a/Lib/idlelib/interruptmodule.c b/Lib/idlelib/interruptmodule.c
new file mode 100644 (file)
index 0000000..8e18d5a
--- /dev/null
@@ -0,0 +1,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);
+}
index 42692735ab6a35405a9e508f625f5b3f40d6b086..a7cff9cefecb0daaf585423901bbecb309db8e8b 100644 (file)
@@ -1,5 +1,5 @@
 import os, glob, sys
-from distutils.core import setup
+from distutils.core import setup, Extension
 from distutils.command.build_py import build_py
 from distutils.command.install_lib import install_lib
 import idlever
@@ -111,5 +111,6 @@ For further details, refer to idlefork.sourceforge.net.
                   'install_lib':IDLE_Installer},
       package_dir = {pkgname: pkg_dir},
       packages = [pkgname],
+      ext_modules = [Extension("interrupt", ["interruptmodule.c"])],
       scripts = [os.path.join(pkg_dir, idle_name)]
       )