Python win32event.WAIT_TIMEOUT Examples

The following are 10 code examples of win32event.WAIT_TIMEOUT(). 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: environments.py    From holodeck with MIT License 6 votes vote down vote up
def __windows_start_process__(self, binary_path, task_key, verbose):
        import win32event
        out_stream = sys.stdout if verbose else open(os.devnull, 'w')
        loading_semaphore = win32event.CreateSemaphore(None, 0, 1,
                                                       'Global\\HOLODECK_LOADING_SEM' + self._uuid)
        self._world_process = \
            subprocess.Popen([binary_path, task_key, '-HolodeckOn', '-LOG=HolodeckLog.txt',
                              '-ForceRes', '-ResX=' + str(self._window_size[1]), '-ResY=' +
                              str(self._window_size[0]), '-TicksPerSec=' + str(self._ticks_per_sec),
                              '--HolodeckUUID=' + self._uuid],
                             stdout=out_stream, stderr=out_stream)

        atexit.register(self.__on_exit__)
        response = win32event.WaitForSingleObject(loading_semaphore, 100000)  # 100 second timeout
        if response == win32event.WAIT_TIMEOUT:
            raise HolodeckException("Timed out waiting for binary to load") 
Example #2
Source File: test_win32event.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testWaitableTrigger(self):
        h = win32event.CreateWaitableTimer(None, 0, None)
        # for the sake of this, pass a long that doesn't fit in an int.
        dt = -2000000000
        win32event.SetWaitableTimer(h, dt, 0, None, None, 0)
        rc = win32event.WaitForSingleObject(h, 10) # 10 ms.
        self.failUnlessEqual(rc, win32event.WAIT_TIMEOUT) 
Example #3
Source File: test_win32event.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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 #4
Source File: test_win32event.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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 #5
Source File: test_win32event.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testMsgWaitForMultipleObjectsEx(self):
        # this function used to segfault when called with an empty list
        res = win32event.MsgWaitForMultipleObjectsEx([], 0, 0, 0)
        self.assertEquals(res, win32event.WAIT_TIMEOUT) 
Example #6
Source File: test_win32event.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testMsgWaitForMultipleObjectsEx2(self):
        # test with non-empty list
        event = win32event.CreateEvent(None, 0, 0, None)
        res = win32event.MsgWaitForMultipleObjectsEx([event], 0, 0, 0)
        self.assertEquals(res, win32event.WAIT_TIMEOUT) 
Example #7
Source File: test_win32file.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def connect_thread_runner(self, expect_payload, giveup_event):
        # As Windows 2000 doesn't do ConnectEx, we need to use a non-blocking
        # accept, as our test connection may never come.  May as well use
        # AcceptEx for this...
        listener = socket.socket()
        self.addr = ('localhost', random.randint(10000,64000))
        listener.bind(self.addr)
        listener.listen(1)

        # create accept socket
        accepter = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # An overlapped
        overlapped = pywintypes.OVERLAPPED()
        overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None)
        # accept the connection.
        if expect_payload:
            buf_size = 1024
        else:
            # when we don't expect data we must be careful to only pass the
            # exact number of bytes for the endpoint data...
            buf_size = win32file.CalculateSocketEndPointSize(listener)

        buffer = win32file.AllocateReadBuffer(buf_size)
        win32file.AcceptEx(listener, accepter, buffer, overlapped)
        # wait for the connection or our test to fail.
        events = giveup_event, overlapped.hEvent
        rc = win32event.WaitForMultipleObjects(events, False, 2000)
        if rc == win32event.WAIT_TIMEOUT:
            self.fail("timed out waiting for a connection")
        if rc == win32event.WAIT_OBJECT_0:
            # Our main thread running the test failed and will never connect.
            return
        # must be a connection.
        nbytes = win32file.GetOverlappedResult(listener.fileno(), overlapped, False)
        if expect_payload:
            self.request = buffer[:nbytes]
        accepter.send(str2bytes('some expected response')) 
Example #8
Source File: dirmon.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
def is_modified(self, buffer):
        print "path", self.path
        result = win32file.ReadDirectoryChangesW(
             self.handle,
             buffer,
             True,
                win32con.FILE_NOTIFY_CHANGE_FILE_NAME 
              | win32con.FILE_NOTIFY_CHANGE_DIR_NAME
              | win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES
              | win32con.FILE_NOTIFY_CHANGE_SIZE
              | win32con.FILE_NOTIFY_CHANGE_LAST_WRITE
              | win32con.FILE_NOTIFY_CHANGE_SECURITY,
             self.overlapped,
            )
        print "result  1", result
        result = win32event.WaitForMultipleObjects([self.overlapped.hEvent], True, 0)
        print "result  2", result
        if result != win32event.WAIT_TIMEOUT:
#            result = win32file.GetOverlappedResult(self.handle, self.overlapped, False)
            return True
        else:
            return False


#===========================================================================
# Directory monitor class. 
Example #9
Source File: win32eventreactor.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
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) 
Example #10
Source File: HID.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def Write(self, data, timeout):
        if self.handle:
            try:
                self.lockObject.acquire()
                if eg.debugLevel:
                    print "writing " + str(len(data)) + " bytes to " + self.getName()
                if not self._overlappedWrite:
                    self._overlappedWrite = win32file.OVERLAPPED()
                err, n = win32file.WriteFile(self.handle, data, self._overlappedWrite)
                if err:  #will be ERROR_IO_PENDING:
                    # Wait for the write to complete.
                    n = win32file.GetOverlappedResult(self.handle, self._overlappedWrite, 1)
                    if n != len(data):
                        raise Exception("could not write full data")
                elif n != len(data):
                    raise Exception("could not write full data")
                if timeout:  #waits for response from device
                    win32event.ResetEvent(self._overlappedRead.hEvent)
                    res = win32event.WaitForSingleObject(self._overlappedRead.hEvent, timeout)
                    if res == win32event.WAIT_TIMEOUT:
                        raise Exception("no response from device within timeout")
            finally:
                self.lockObject.release()
        else:
            raise Exception("invalid handle")
            return