summaryrefslogtreecommitdiffstats
path: root/Modules/timemodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-11-21 20:26:56 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-11-21 20:26:56 (GMT)
commit6dd381eb62278f75de7ba01626813de84cd248e7 (patch)
tree4b843b5767b3296212c5dbe8c696c1081b2fbfe0 /Modules/timemodule.c
parentce4a9da70535b4bb9048147b141f01004af2133d (diff)
downloadcpython-6dd381eb62278f75de7ba01626813de84cd248e7.zip
cpython-6dd381eb62278f75de7ba01626813de84cd248e7.tar.gz
cpython-6dd381eb62278f75de7ba01626813de84cd248e7.tar.bz2
Issue #12328: Under Windows, refactor handling of Ctrl-C events and
make _multiprocessing.win32.WaitForMultipleObjects interruptible when the wait_flag parameter is false. Patch by sbt.
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r--Modules/timemodule.c30
1 files changed, 2 insertions, 28 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 85614a6..52aade4 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -21,19 +21,6 @@
#include <windows.h>
#include "pythread.h"
-/* helper to allow us to interrupt sleep() on Windows*/
-static HANDLE hInterruptEvent = NULL;
-static BOOL WINAPI PyCtrlHandler(DWORD dwCtrlType)
-{
- SetEvent(hInterruptEvent);
- /* allow other default handlers to be called.
- Default Python handler will setup the
- KeyboardInterrupt exception.
- */
- return FALSE;
-}
-static long main_thread;
-
#if defined(__BORLANDC__)
/* These overrides not needed for Win32 */
#define timezone _timezone
@@ -955,15 +942,6 @@ PyInit_time(void)
/* Set, or reset, module variables like time.timezone */
PyInit_timezone(m);
-#ifdef MS_WINDOWS
- /* Helper to allow interrupts for Windows.
- If Ctrl+C event delivered while not sleeping
- it will be ignored.
- */
- main_thread = PyThread_get_thread_ident();
- hInterruptEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- SetConsoleCtrlHandler( PyCtrlHandler, TRUE);
-#endif /* MS_WINDOWS */
if (!initialized) {
PyStructSequence_InitType(&StructTimeType,
&struct_time_type_desc);
@@ -1036,18 +1014,14 @@ floatsleep(double secs)
* by Guido, only the main thread can be interrupted.
*/
ul_millis = (unsigned long)millisecs;
- if (ul_millis == 0 ||
- main_thread != PyThread_get_thread_ident())
+ if (ul_millis == 0 || !_PyOS_IsMainThread())
Sleep(ul_millis);
else {
DWORD rc;
+ HANDLE hInterruptEvent = _PyOS_SigintEvent();
ResetEvent(hInterruptEvent);
rc = WaitForSingleObject(hInterruptEvent, ul_millis);
if (rc == WAIT_OBJECT_0) {
- /* Yield to make sure real Python signal
- * handler called.
- */
- Sleep(1);
Py_BLOCK_THREADS
errno = EINTR;
PyErr_SetFromErrno(PyExc_IOError);