From 8398813ffc0159e21a878c04d346188e46d2bba1 2011-07-17 22:07:36 From: Min Ragan-Kelley Date: 2011-07-17 22:07:36 Subject: [PATCH] handle different pointer size on x64 Windows WindowsParentPoller makes a winapi call, and needs to handle 32/64b pointer difference. This commit adds switching of c_int vs c_int64, depending on platform.architecture(). It also prevents hogging CPU by adding a short sleep in possible cases where the call still fails. closes gh-588 --- diff --git a/IPython/zmq/parentpoller.py b/IPython/zmq/parentpoller.py index 36da698..a9bfabb 100644 --- a/IPython/zmq/parentpoller.py +++ b/IPython/zmq/parentpoller.py @@ -1,6 +1,7 @@ # Standard library imports. import ctypes import os +import platform import time from thread import interrupt_main from threading import Thread @@ -100,12 +101,14 @@ class ParentPollerWindows(Thread): handles.append(self.interrupt_handle) if self.parent_handle: handles.append(self.parent_handle) + arch = platform.architecture()[0] + c_int = ctypes.c_int64 if arch.startswith('64') else ctypes.c_int # Listen forever. while True: result = ctypes.windll.kernel32.WaitForMultipleObjects( len(handles), # nCount - (ctypes.c_int * len(handles))(*handles), # lpHandles + (c_int * len(handles))(*handles), # lpHandles False, # bWaitAll INFINITE) # dwMilliseconds @@ -117,3 +120,8 @@ class ParentPollerWindows(Thread): elif handle == self.parent_handle: os._exit(1) + elif result < 0: + # wait failed, but don't let this throttle CPU + # if this is going to repeat, perhaps we should + # just give up and return. + time.sleep(.1)