diff -r 8cf192a6fabe Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py Wed Jun 15 13:02:28 2011 +0100 +++ b/Lib/multiprocessing/connection.py Wed Jun 15 13:15:15 2011 +0100 @@ -51,7 +51,7 @@ from multiprocessing.util import ( get_temp_dir, Finalize, sub_debug, debug, _eintr_retry) try: - from _multiprocessing import win32 + from _multiprocessing import win32, sigint_event from _subprocess import WAIT_OBJECT_0, WAIT_TIMEOUT, INFINITE except ImportError: if sys.platform == 'win32': @@ -381,6 +381,27 @@ assert 0 < idx < len(handles) raise SentinelReady([handles[idx]]) + def poll(self, timeout=0.0): + """Whether there is any input available to be read""" + self._check_closed() + self._check_readable() + if timeout > 0.0: + end = time.time() + timeout + while True: + try: + win32.ResetEvent(sigint_event) + return self._poll(timeout, (sigint_event,)) + except SentinelReady: + if timeout == 0.0: + return False + elif timeout > 0.0: + timeout = end - time.time() + if timeout <= 0.0: + return False + # give final chance for KeyboardInterrupt to be + # raised if this is main thread + time.sleep(0.001) + class Connection(_ConnectionBase): """ diff -r 8cf192a6fabe Modules/_multiprocessing/multiprocessing.c --- a/Modules/_multiprocessing/multiprocessing.c Wed Jun 15 13:02:28 2011 +0100 +++ b/Modules/_multiprocessing/multiprocessing.c Wed Jun 15 13:15:15 2011 +0100 @@ -276,6 +276,7 @@ PyErr_SetFromWindowsErr(0); return NULL; } + PyModule_AddIntConstant(module, "sigint_event", (long)sigint_event); #endif /* Add configuration macros */ diff -r 8cf192a6fabe Modules/_multiprocessing/win32_functions.c --- a/Modules/_multiprocessing/win32_functions.c Wed Jun 15 13:02:28 2011 +0100 +++ b/Modules/_multiprocessing/win32_functions.c Wed Jun 15 13:15:15 2011 +0100 @@ -426,6 +426,25 @@ } static PyObject * +win32_ResetEvent(PyObject *self, PyObject *args) +{ + HANDLE hObject; + BOOL success; + + if (!PyArg_ParseTuple(args, F_HANDLE, &hObject)) + return NULL; + + Py_BEGIN_ALLOW_THREADS + success = ResetEvent(hObject); + Py_END_ALLOW_THREADS + + if (!success) + return PyErr_SetFromWindowsErr(0); + + Py_RETURN_NONE; +} + +static PyObject * win32_SetNamedPipeHandleState(PyObject *self, PyObject *args) { HANDLE hNamedPipe; @@ -756,6 +775,7 @@ WIN32_FUNCTION(CreateNamedPipe), WIN32_KWARGS_FUNCTION(ReadFile), WIN32_FUNCTION(PeekNamedPipe), + WIN32_FUNCTION(ResetEvent), WIN32_FUNCTION(SetNamedPipeHandleState), WIN32_FUNCTION(WaitForMultipleObjects), WIN32_FUNCTION(WaitNamedPipe),