Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37729489
en ru br
ALT Linux repos
S:2.7.18-alt11
5.0: 2.5.4-alt5
4.1: 2.5.4-alt0.M41.1
4.0: 2.4.5-alt0.M40.1
3.0: 2.4.1-alt5

Group :: Development/Python
RPM: python

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

Patch: python-2.5.2-set_wakeup_fd4.patch
Download


diff -ru Python-2.5.2-orig/Modules/signalmodule.c Python-2.5.2/Modules/signalmodule.c
--- Python-2.5.2-orig/Modules/signalmodule.c	2007-12-10 18:03:55.000000000 -0500
+++ Python-2.5.2/Modules/signalmodule.c	2008-09-24 17:32:45.000000000 -0400
@@ -12,6 +12,8 @@
 
 #include <signal.h>
 
+#include <sys/stat.h>
+
 #ifndef SIG_ERR
 #define SIG_ERR ((PyOS_sighandler_t)(-1))
 #endif
@@ -75,6 +77,8 @@
         PyObject *func;
 } Handlers[NSIG];
 
+static int wakeup_fd = -1;
+
 /* Speed up sigcheck() when none tripped */
 static volatile sig_atomic_t is_tripped = 0;
 
@@ -113,6 +117,7 @@
 static void
 signal_handler(int sig_num)
 {
+	const char dummy_byte = '\0';
 #ifdef WITH_THREAD
 #ifdef WITH_PTH
 	if (PyThread_get_thread_ident() != main_thread) {
@@ -128,6 +133,8 @@
                    cleared in PyErr_CheckSignals() before .tripped. */
 		is_tripped = 1;
 		Py_AddPendingCall(checksignals_witharg, NULL);
+		if (wakeup_fd != -1)
+			write(wakeup_fd, &dummy_byte, 1);
 #ifdef WITH_THREAD
 	}
 #endif
@@ -267,6 +274,39 @@
 anything else -- the callable Python object used as a handler");
 
 
+static PyObject *
+signal_set_wakeup_fd(PyObject *self, PyObject *args)
+{
+	struct stat buf;
+	int fd, old_fd;
+	if (!PyArg_ParseTuple(args, "i:set_wakeup_fd", &fd))
+		return NULL;
+#ifdef WITH_THREAD
+	if (PyThread_get_thread_ident() != main_thread) {
+		PyErr_SetString(PyExc_ValueError,
+				"set_wakeup_fd only works in main thread");
+		return NULL;
+	}
+#endif
+	if (fd != -1 && fstat(fd, &buf) != 0) {
+		PyErr_SetString(PyExc_ValueError, "invalid fd");
+		return NULL;
+	}
+	old_fd = wakeup_fd;
+	wakeup_fd = fd;
+	return PyLong_FromLong(old_fd);
+}
+
+PyDoc_STRVAR(set_wakeup_fd_doc,
+"set_wakeup_fd(fd) -> fd\n\
+\n\
+Sets the fd to be written to (with '\\0') when a signal\n\
+comes in.  A library can use this to wakeup select or poll.\n\
+The previous fd is returned.\n\
+\n\
+The fd must be non-blocking.");
+
+
 /* List of functions defined in the module */
 static PyMethodDef signal_methods[] = {
 #ifdef HAVE_ALARM
@@ -274,6 +314,7 @@
 #endif
 	{"signal",	        signal_signal, METH_VARARGS, signal_doc},
 	{"getsignal",	        signal_getsignal, METH_VARARGS, getsignal_doc},
+	{"set_wakeup_fd",	signal_set_wakeup_fd, METH_VARARGS, set_wakeup_fd_doc},
 #ifdef HAVE_PAUSE
 	{"pause",	        (PyCFunction)signal_pause,
 	 METH_NOARGS,pause_doc},
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin