1 diff -rup Python-2.5.1-orig/Modules/signalmodule.c Python-2.5.1/Modules/signalmodule.c
2 --- Python-2.5.1-orig/Modules/signalmodule.c 2006-01-19 01:09:39.000000000 -0500
3 +++ Python-2.5.1/Modules/signalmodule.c 2008-01-07 12:32:00.000000000 -0500
11 #define SIG_ERR ((PyOS_sighandler_t)(-1))
13 @@ -75,6 +77,8 @@ static struct {
17 +static int wakeup_fd = -1;
19 static int is_tripped = 0; /* Speed up sigcheck() when none tripped */
21 static PyObject *DefaultHandler;
22 @@ -112,6 +116,7 @@ checksignals_witharg(void * unused)
24 signal_handler(int sig_num)
26 + const char dummy_byte = '\0';
29 if (PyThread_get_thread_ident() != main_thread) {
30 @@ -125,6 +130,8 @@ signal_handler(int sig_num)
32 Handlers[sig_num].tripped = 1;
33 Py_AddPendingCall(checksignals_witharg, NULL);
34 + if (wakeup_fd != -1)
35 + write(wakeup_fd, &dummy_byte, 1);
39 @@ -264,6 +271,39 @@ None -- if an unknown handler is in effe
40 anything else -- the callable Python object used as a handler");
44 +signal_set_wakeup_fd(PyObject *self, PyObject *args)
48 + if (!PyArg_ParseTuple(args, "i:set_wakeup_fd", &fd))
51 + if (PyThread_get_thread_ident() != main_thread) {
52 + PyErr_SetString(PyExc_ValueError,
53 + "set_wakeup_fd only works in main thread");
57 + if (fd != -1 && fstat(fd, &buf) != 0) {
58 + PyErr_SetString(PyExc_ValueError, "invalid fd");
63 + return PyLong_FromLong(old_fd);
66 +PyDoc_STRVAR(set_wakeup_fd_doc,
67 +"set_wakeup_fd(fd) -> fd\n\
69 +Sets the fd to be written to (with '\\0') when a signal\n\
70 +comes in. A library can use this to wakeup select or poll.\n\
71 +The previous fd is returned.\n\
73 +The fd must be non-blocking.");
76 /* List of functions defined in the module */
77 static PyMethodDef signal_methods[] = {
79 @@ -271,6 +311,7 @@ static PyMethodDef signal_methods[] = {
81 {"signal", signal_signal, METH_VARARGS, signal_doc},
82 {"getsignal", signal_getsignal, METH_VARARGS, getsignal_doc},
83 + {"set_wakeup_fd", signal_set_wakeup_fd, METH_VARARGS, set_wakeup_fd_doc},
85 {"pause", (PyCFunction)signal_pause,
86 METH_NOARGS,pause_doc},