Python win32event.WaitForMultipleObjects() Examples

The following are 10 code examples of win32event.WaitForMultipleObjects(). 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: win32.py    From cherrypy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def wait(self, state, interval=0.1, channel=None):
        """Wait for the given state(s), KeyboardInterrupt or SystemExit.

        Since this class uses native win32event objects, the interval
        argument is ignored.
        """
        if isinstance(state, (tuple, list)):
            # Don't wait for an event that beat us to the punch ;)
            if self.state not in state:
                events = tuple([self._get_state_event(s) for s in state])
                win32event.WaitForMultipleObjects(
                    events, 0, win32event.INFINITE)
        else:
            # Don't wait for an event that beat us to the punch ;)
            if self.state != state:
                event = self._get_state_event(state)
                win32event.WaitForSingleObject(event, win32event.INFINITE) 
Example #2
Source File: TraceCollector.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def CollectorThread(stopEvent, file):
	win32trace.InitRead()
	handle = win32trace.GetHandle()
	# Run this thread at a lower priority to the main message-loop (and printing output)
	# thread can keep up
	import win32process
	win32process.SetThreadPriority(win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_BELOW_NORMAL)

	try:
		while 1:
			rc = win32event.WaitForMultipleObjects((handle, stopEvent), 0, win32event.INFINITE)
			if rc == win32event.WAIT_OBJECT_0:
				# About the only char we can't live with is \0!
				file.write(win32trace.read().replace("\0", "<null>"))
			else:
				# Stop event
				break
	finally:
		win32trace.TermRead()
		print "Thread dieing" 
Example #3
Source File: document.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def Run(self):
		while 1:
			handles = [self.stopEvent, self.adminEvent]
			if self.watchEvent is not None:
				handles.append(self.watchEvent)
			rc = win32event.WaitForMultipleObjects(handles, 0, win32event.INFINITE)
			if rc == win32event.WAIT_OBJECT_0:
				break
			elif rc == win32event.WAIT_OBJECT_0+1:
				self.RefreshEvent()
			else:
				win32api.PostMessage(self.hwnd, MSG_CHECK_EXTERNAL_FILE, 0, 0)
				try:
					# If the directory has been removed underneath us, we get this error.
					win32api.FindNextChangeNotification(self.watchEvent)
				except win32api.error, exc:
					print "Can not watch file", self.doc.GetPathName(), "for changes -", exc.strerror
					break

		# close a circular reference 
Example #4
Source File: win32.py    From opsbro with MIT License 6 votes vote down vote up
def wait(self, state, interval=0.1, channel=None):
        """Wait for the given state(s), KeyboardInterrupt or SystemExit.

        Since this class uses native win32event objects, the interval
        argument is ignored.
        """
        if isinstance(state, (tuple, list)):
            # Don't wait for an event that beat us to the punch ;)
            if self.state not in state:
                events = tuple([self._get_state_event(s) for s in state])
                win32event.WaitForMultipleObjects(
                    events, 0, win32event.INFINITE)
        else:
            # Don't wait for an event that beat us to the punch ;)
            if self.state != state:
                event = self._get_state_event(state)
                win32event.WaitForSingleObject(event, win32event.INFINITE) 
Example #5
Source File: win32.py    From bazarr with GNU General Public License v3.0 6 votes vote down vote up
def wait(self, state, interval=0.1, channel=None):
        """Wait for the given state(s), KeyboardInterrupt or SystemExit.

        Since this class uses native win32event objects, the interval
        argument is ignored.
        """
        if isinstance(state, (tuple, list)):
            # Don't wait for an event that beat us to the punch ;)
            if self.state not in state:
                events = tuple([self._get_state_event(s) for s in state])
                win32event.WaitForMultipleObjects(
                    events, 0, win32event.INFINITE)
        else:
            # Don't wait for an event that beat us to the punch ;)
            if self.state != state:
                event = self._get_state_event(state)
                win32event.WaitForSingleObject(event, win32event.INFINITE) 
Example #6
Source File: win32.py    From Tautulli with GNU General Public License v3.0 6 votes vote down vote up
def wait(self, state, interval=0.1, channel=None):
        """Wait for the given state(s), KeyboardInterrupt or SystemExit.

        Since this class uses native win32event objects, the interval
        argument is ignored.
        """
        if isinstance(state, (tuple, list)):
            # Don't wait for an event that beat us to the punch ;)
            if self.state not in state:
                events = tuple([self._get_state_event(s) for s in state])
                win32event.WaitForMultipleObjects(
                    events, 0, win32event.INFINITE)
        else:
            # Don't wait for an event that beat us to the punch ;)
            if self.state != state:
                event = self._get_state_event(state)
                win32event.WaitForSingleObject(event, win32event.INFINITE) 
Example #7
Source File: win32.py    From moviegrabber with GNU General Public License v3.0 6 votes vote down vote up
def wait(self, state, interval=0.1, channel=None):
        """Wait for the given state(s), KeyboardInterrupt or SystemExit.
        
        Since this class uses native win32event objects, the interval
        argument is ignored.
        """
        if isinstance(state, (tuple, list)):
            # Don't wait for an event that beat us to the punch ;)
            if self.state not in state:
                events = tuple([self._get_state_event(s) for s in state])
                win32event.WaitForMultipleObjects(events, 0, win32event.INFINITE)
        else:
            # Don't wait for an event that beat us to the punch ;)
            if self.state != state:
                event = self._get_state_event(state)
                win32event.WaitForSingleObject(event, win32event.INFINITE) 
Example #8
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 #9
Source File: loglib.py    From CVE-2016-6366 with MIT License 5 votes vote down vote up
def pacemaker(self, timeout=60):
    #   This is a stand-alone heartbeat generator.  To pulse from your own control loop,
    #   call your AbstractLog subclass instance event handler (e.g. AbstractLog['event']()
        def __target(timeout=60):
            if platform.uname()[0].lower() == "windows":
                import win32con
                import win32event
                self.running = True
                kill = win32event.CreateEvent(None, 1, 0, None)
                pulse = win32event.CreateWaitableTimer(None, 0, None)
                win32event.SetWaitableTimer(pulse, 0, timeout*1000, None, None, False)
                while(self.running):
                    try:
                        result = win32event.WaitForMultipleObjects([kill, pulse], False, 1000)
                        
                        # if kill signal received, break loop
                        if(result == win32con.WAIT_OBJECT_0): break
                        # elif timeout has passed, generate a pulse
                        elif(result == win32con.WAIT_OBJECT_0 + 1): self['event']()
                    except:
                        self.notifyOfError("Pacemaker shutdown.  Heartbeats will not be generated.")
                        win32event.SetEvent(kill)
            elif self.options['Verbose']: print "Pacemaker only supported in Windows at this time. " 
       
        try:
            self.thread = threading.Thread(target=__target, args=(timeout,) )
            self.thread.start()
        except:
            self.notifyOfError("Pacemaker thread exception.  Heartbeats will not be generated.") 
Example #10
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.