cpython: fbd104359ef8 (original) (raw)

Mercurial > cpython

changeset 91933:fbd104359ef8

Issue #22018: On Windows, signal.set_wakeup_fd() now also supports sockets. A side effect is that Python depends to the WinSock library. [#22018]

Victor Stinner victor.stinner@gmail.com
date Tue, 29 Jul 2014 23:31:34 +0200
parents 741e58bcaa65
children 79a5fbe2c78f
files Doc/c-api/exceptions.rst Doc/library/signal.rst Lib/test/test_signal.py Misc/NEWS Modules/signalmodule.c PCbuild/pythoncore.vcxproj
diffstat 6 files changed, 294 insertions(+), 29 deletions(-)[+] [-] Doc/c-api/exceptions.rst 11 Doc/library/signal.rst 3 Lib/test/test_signal.py 107 Misc/NEWS 3 Modules/signalmodule.c 183 PCbuild/pythoncore.vcxproj 16

line wrap: on

line diff

--- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -443,13 +443,18 @@ in various ways. There is a separate er .. c:function:: int PySignal_SetWakeupFd(int fd)

+ .. c:function:: PyObject* PyErr_NewException(char *name, PyObject *base, PyObject *dict)

--- a/Doc/library/signal.rst +++ b/Doc/library/signal.rst @@ -318,6 +318,9 @@ The :mod:signal module defines the fol attempting to call it from other threads will cause a :exc:ValueError exception to be raised.

+ .. function:: siginterrupt(signalnum, flag)

--- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -6,6 +6,7 @@ import gc import pickle import select import signal +import socket import struct import subprocess import traceback @@ -255,6 +256,13 @@ class WakeupFDTests(unittest.TestCase): self.assertRaises((ValueError, OSError), signal.set_wakeup_fd, fd)

+ def test_set_wakeup_fd_result(self): r1, w1 = os.pipe() self.addCleanup(os.close, r1) @@ -268,6 +276,20 @@ class WakeupFDTests(unittest.TestCase): self.assertEqual(signal.set_wakeup_fd(-1), w2) self.assertEqual(signal.set_wakeup_fd(-1), -1)

+

+

+ @unittest.skipIf(sys.platform == "win32", "Not valid on Windows") class WakeupSignalTests(unittest.TestCase): @@ -435,6 +457,90 @@ class WakeupSignalTests(unittest.TestCas """, signal.SIGUSR1, signal.SIGUSR2, ordered=False) +@unittest.skipUnless(hasattr(socket, 'socketpair'), 'need socket.socketpair') +class WakeupSocketSignalTests(unittest.TestCase): +

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+ + @unittest.skipIf(sys.platform == "win32", "Not valid on Windows") class SiginterruptTest(unittest.TestCase): @@ -984,6 +1090,7 @@ def test_main(): try: support.run_unittest(GenericTests, PosixTests, InterProcessSignalTests, WakeupFDTests, WakeupSignalTests,

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -113,6 +113,9 @@ Core and Builtins Library ------- +- Issue #22018: On Windows, signal.set_wakeup_fd() now also supports sockets.

--- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -7,6 +7,9 @@ #ifndef MS_WINDOWS #include "posixmodule.h" #endif +#ifdef MS_WINDOWS +#include "socketmodule.h" /* needed for SOCKET_T */ +#endif #ifdef MS_WINDOWS #include <windows.h> @@ -87,7 +90,20 @@ static volatile struct { PyObject *func; } Handlers[NSIG]; +#ifdef MS_WINDOWS +#define INVALID_FD ((SOCKET_T)-1) + +static volatile struct {

+} wakeup = {INVALID_FD, 0, 0}; +#else +#define INVALID_FD (-1) static volatile sig_atomic_t wakeup_fd = -1; +#endif /* Speed up sigcheck() when none tripped */ static volatile sig_atomic_t is_tripped = 0; @@ -172,7 +188,7 @@ checksignals_witharg(void * unused) } static int -report_wakeup_error(void *data) +report_wakeup_write_error(void *data) { int save_errno = errno; errno = (int) (Py_intptr_t) data; @@ -184,25 +200,86 @@ report_wakeup_error(void data) return 0; } +#ifdef MS_WINDOWS +static int +report_wakeup_send_error(void Py_UNUSED(data)) +{

+

+

+

+

+} +#endif /* MS_WINDOWS */ + static void trip_signal(int sig_num) { unsigned char byte;

Handlers[sig_num].tripped = 1;

+ +#ifdef MS_WINDOWS

+#else

+#endif +

+#ifdef MS_WINDOWS

+

+#endif

+

+

} static void @@ -426,10 +503,29 @@ signal_siginterrupt(PyObject *self, PyOb static PyObject * signal_set_wakeup_fd(PyObject *self, PyObject *args) {

+#ifdef MS_WINDOWS

+

+

+#else int fd, old_fd;

+ if (!PyArg_ParseTuple(args, "i:set_wakeup_fd", &fd)) return NULL; +#endif + #ifdef WITH_THREAD if (PyThread_get_thread_ident() != main_thread) { PyErr_SetString(PyExc_ValueError, @@ -438,28 +534,72 @@ signal_set_wakeup_fd(PyObject *self, PyO } #endif +#ifdef MS_WINDOWS

+

+

+

+

+

+#else if (fd != -1) { if (!_PyVerify_fd(fd)) { PyErr_SetString(PyExc_ValueError, "invalid fd"); return NULL; }

+ +#ifdef MS_WINDOWS

+#else

--- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -176,7 +176,7 @@ "$(SolutionDir)make_buildinfo.exe" Release "$(IntDir)"

@@ -212,7 +212,7 @@ IF %ERRORLEVEL% NEQ 0 ( "$(SolutionDir)make_buildinfo.exe" Release "$(IntDir)"

@@ -353,7 +353,7 @@ IF %ERRORLEVEL% NEQ 0 ( "$(SolutionDir)make_buildinfo.exe" Release "$(IntDir)"

@@ -386,7 +386,7 @@ IF %ERRORLEVEL% NEQ 0 ( "$(SolutionDir)make_buildinfo.exe" Release "$(IntDir)"

@@ -422,7 +422,7 @@ IF %ERRORLEVEL% NEQ 0 ( "$(SolutionDir)make_buildinfo.exe" Release "$(IntDir)"