1 diff -ru Python-2.5.2-orig/Modules/signalmodule.c Python-2.5.2/Modules/signalmodule.c
2 --- Python-2.5.2-orig/Modules/signalmodule.c 2007-12-10 18:03:55.000000000 -0500
3 +++ Python-2.5.2/Modules/signalmodule.c 2008-09-24 17:32:45.000000000 -0400
11 #define SIG_ERR ((PyOS_sighandler_t)(-1))
17 +static int wakeup_fd = -1;
19 /* Speed up sigcheck() when none tripped */
20 static volatile sig_atomic_t is_tripped = 0;
24 signal_handler(int sig_num)
26 + const char dummy_byte = '\0';
29 if (PyThread_get_thread_ident() != main_thread) {
31 cleared in PyErr_CheckSignals() before .tripped. */
33 Py_AddPendingCall(checksignals_witharg, NULL);
34 + if (wakeup_fd != -1)
35 + write(wakeup_fd, &dummy_byte, 1);
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[] = {
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},