Python win32event.MsgWaitForMultipleObjects() Examples
The following are 6
code examples of win32event.MsgWaitForMultipleObjects().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32event
, or try the search function
.
Example #1
Source File: eventsApartmentThreaded.py From ironpython2 with Apache License 2.0 | 8 votes |
def WaitWhileProcessingMessages(event, timeout = 2): start = time.clock() while True: # Wake 4 times a second - we can't just specify the # full timeout here, as then it would reset for every # message we process. rc = win32event.MsgWaitForMultipleObjects( (event,), 0, 250, win32event.QS_ALLEVENTS) if rc == win32event.WAIT_OBJECT_0: # event signalled - stop now! return True if (time.clock() - start) > timeout: # Timeout expired. return False # must be a message. pythoncom.PumpWaitingMessages()
Example #2
Source File: testGIT.py From ironpython2 with Apache License 2.0 | 6 votes |
def test(fn): print "The main thread is %d" % (win32api.GetCurrentThreadId()) GIT = CreateGIT() interp = win32com.client.Dispatch("Python.Interpreter") cookie = GIT.RegisterInterfaceInGlobal(interp._oleobj_, pythoncom.IID_IDispatch) events = fn(4, cookie) numFinished = 0 while 1: try: rc = win32event.MsgWaitForMultipleObjects(events, 0, 2000, win32event.QS_ALLINPUT) if rc >= win32event.WAIT_OBJECT_0 and rc < win32event.WAIT_OBJECT_0+len(events): numFinished = numFinished + 1 if numFinished >= len(events): break elif rc==win32event.WAIT_OBJECT_0 + len(events): # a message # This is critical - whole apartment model demo will hang. pythoncom.PumpWaitingMessages() else: # Timeout print "Waiting for thread to stop with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) except KeyboardInterrupt: break GIT.RevokeInterfaceFromGlobal(cookie) del interp del GIT
Example #3
Source File: timer_demo.py From ironpython2 with Apache License 2.0 | 5 votes |
def demo (delay=1000, stop=10): g = glork(delay, stop) # Timers are message based - so we need # To run a message loop while waiting for our timers # to expire. start_time = time.time() while 1: # We can't simply give a timeout of 30 seconds, as # we may continouusly be recieving other input messages, # and therefore never expire. rc = win32event.MsgWaitForMultipleObjects( (g.event,), # list of objects 0, # wait all 500, # timeout win32event.QS_ALLEVENTS, # type of input ) if rc == win32event.WAIT_OBJECT_0: # Event signalled. break elif rc == win32event.WAIT_OBJECT_0+1: # Message waiting. if win32gui.PumpWaitingMessages(): raise RuntimeError("We got an unexpected WM_QUIT message!") else: # This wait timed-out. if time.time()-start_time > 30: raise RuntimeError("We timed out waiting for the timers to expire!")
Example #4
Source File: test_win32event.py From ironpython2 with Apache License 2.0 | 5 votes |
def testMsgWaitForMultipleObjects(self): # this function used to segfault when called with an empty list res = win32event.MsgWaitForMultipleObjects([], 0, 0, 0) self.assertEquals(res, win32event.WAIT_TIMEOUT)
Example #5
Source File: test_win32event.py From ironpython2 with Apache License 2.0 | 5 votes |
def testMsgWaitForMultipleObjects2(self): # test with non-empty list event = win32event.CreateEvent(None, 0, 0, None) res = win32event.MsgWaitForMultipleObjects([event], 0, 0, 0) self.assertEquals(res, win32event.WAIT_TIMEOUT)
Example #6
Source File: win32eventreactor.py From python-for-android with Apache License 2.0 | 5 votes |
def doWaitForMultipleEvents(self, timeout): log.msg(channel='system', event='iteration', reactor=self) if timeout is None: #timeout = INFINITE timeout = 100 else: timeout = int(timeout * 1000) if not (self._events or self._writes): # sleep so we don't suck up CPU time time.sleep(timeout / 1000.0) return canDoMoreWrites = 0 for fd in self._writes.keys(): if log.callWithLogger(fd, self._runWrite, fd): canDoMoreWrites = 1 if canDoMoreWrites: timeout = 0 handles = self._events.keys() or [self.dummyEvent] val = MsgWaitForMultipleObjects(handles, 0, timeout, QS_ALLINPUT | QS_ALLEVENTS) if val == WAIT_TIMEOUT: return elif val == WAIT_OBJECT_0 + len(handles): exit = win32gui.PumpWaitingMessages() if exit: self.callLater(0, self.stop) return elif val >= WAIT_OBJECT_0 and val < WAIT_OBJECT_0 + len(handles): fd, action = self._events[handles[val - WAIT_OBJECT_0]] log.callWithLogger(fd, self._runAction, action, fd)