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 static int is_tripped = 0; /* Speed up sigcheck() when none tripped */
34 static PyObject *DefaultHandler;
37 signal_handler(int sig_num)
39 + const char dummy_byte = '\0';
42 if (PyThread_get_thread_ident() != main_thread) {
45 Handlers[sig_num].tripped = 1;
46 Py_AddPendingCall(checksignals_witharg, NULL);
47 + if (wakeup_fd != -1)
48 + write(wakeup_fd, &dummy_byte, 1);
53 anything else -- the callable Python object used as a handler");
57 +signal_set_wakeup_fd(PyObject *self, PyObject *args)
61 + if (!PyArg_ParseTuple(args, "i:set_wakeup_fd", &fd))
64 + if (PyThread_get_thread_ident() != main_thread) {
65 + PyErr_SetString(PyExc_ValueError,
66 + "set_wakeup_fd only works in main thread");
70 + if (fd != -1 && fstat(fd, &buf) != 0) {
71 + PyErr_SetString(PyExc_ValueError, "invalid fd");
76 + return PyLong_FromLong(old_fd);
79 +PyDoc_STRVAR(set_wakeup_fd_doc,
80 +"set_wakeup_fd(fd) -> fd\n\
82 +Sets the fd to be written to (with '\\0') when a signal\n\
83 +comes in. A library can use this to wakeup select or poll.\n\
84 +The previous fd is returned.\n\
86 +The fd must be non-blocking.");
88 +/* C API for the same, without all the error checking */
90 +PySignal_SetWakeupFd(int fd)
92 + int old_fd = wakeup_fd;
100 /* List of functions defined in the module */
101 static PyMethodDef signal_methods[] = {
105 {"signal", signal_signal, METH_VARARGS, signal_doc},
106 {"getsignal", signal_getsignal, METH_VARARGS, getsignal_doc},
107 + {"set_wakeup_fd", signal_set_wakeup_fd, METH_VARARGS, set_wakeup_fd_doc},
109 {"pause", (PyCFunction)signal_pause,
110 METH_NOARGS,pause_doc},