1 diff -urN Python-2.5.1.orig/Include/pyerrors.h Python-2.5.1/Include/pyerrors.h
2 --- Python-2.5.1.orig/Include/pyerrors.h 2008-08-10 13:46:48.000000000 +0200
3 +++ Python-2.5.1/Include/pyerrors.h 2008-08-10 13:51:05.000000000 +0200
5 PyAPI_FUNC(int) PyErr_CheckSignals(void);
6 PyAPI_FUNC(void) PyErr_SetInterrupt(void);
8 +/* In signalmodule.c */
9 +int PySignal_SetWakeupFd(int fd);
11 /* Support for adding program text to SyntaxErrors */
12 PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
13 PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);
14 diff -urN Python-2.5.1.orig/Modules/signalmodule.c Python-2.5.1/Modules/signalmodule.c
15 --- Python-2.5.1.orig/Modules/signalmodule.c 2008-08-10 13:46:48.000000000 +0200
16 +++ Python-2.5.1/Modules/signalmodule.c 2008-08-10 13:50:02.000000000 +0200
21 +#include <sys/stat.h>
24 #define SIG_ERR ((PyOS_sighandler_t)(-1))
30 +static int wakeup_fd = -1;
32 /* Speed up sigcheck() when none tripped */
35 signal_handler(int sig_num)
37 + const char dummy_byte = '\0';
40 if (PyThread_get_thread_ident() != main_thread) {
43 Handlers[sig_num].tripped = 1;
44 Py_AddPendingCall(checksignals_witharg, NULL);
45 + if (wakeup_fd != -1)
46 + write(wakeup_fd, &dummy_byte, 1);
51 anything else -- the callable Python object used as a handler");
55 +signal_set_wakeup_fd(PyObject *self, PyObject *args)
59 + if (!PyArg_ParseTuple(args, "i:set_wakeup_fd", &fd))
62 + if (PyThread_get_thread_ident() != main_thread) {
63 + PyErr_SetString(PyExc_ValueError,
64 + "set_wakeup_fd only works in main thread");
68 + if (fd != -1 && fstat(fd, &buf) != 0) {
69 + PyErr_SetString(PyExc_ValueError, "invalid fd");
74 + return PyLong_FromLong(old_fd);
77 +PyDoc_STRVAR(set_wakeup_fd_doc,
78 +"set_wakeup_fd(fd) -> fd\n\
80 +Sets the fd to be written to (with '\\0') when a signal\n\
81 +comes in. A library can use this to wakeup select or poll.\n\
82 +The previous fd is returned.\n\
84 +The fd must be non-blocking.");
86 +/* C API for the same, without all the error checking */
88 +PySignal_SetWakeupFd(int fd)
90 + int old_fd = wakeup_fd;
98 /* List of functions defined in the module */
99 static PyMethodDef signal_methods[] = {
103 {"signal", signal_signal, METH_VARARGS, signal_doc},
104 {"getsignal", signal_getsignal, METH_VARARGS, getsignal_doc},
105 + {"set_wakeup_fd", signal_set_wakeup_fd, METH_VARARGS, set_wakeup_fd_doc},
107 {"pause", (PyCFunction)signal_pause,
108 METH_NOARGS,pause_doc},