Python win32event.INFINITE Examples
The following are 30
code examples of win32event.INFINITE().
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 bazarr with GNU General Public License v3.0 | 6 votes |
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: admin.py From uac-a-mola with GNU General Public License v3.0 | 6 votes |
def runAsAdmin(cmdLine=None, wait=True): if os.name != 'nt': raise RuntimeError, "This function is only implemented on Windows." import win32api import win32con import win32event import win32process from win32com.shell.shell import ShellExecuteEx from win32com.shell import shellcon python_exe = sys.executable if cmdLine is None: cmdLine = [python_exe] + sys.argv elif type(cmdLine) not in (types.TupleType, types.ListType): raise ValueError, "cmdLine is not a sequence." cmd = '"%s"' % (cmdLine[0],) # XXX TODO: isn't there a function or something we can call to massage command line params? params = " ".join(['"%s"' % (x,) for x in cmdLine[1:]]) cmdDir = '' #showCmd = win32con.SW_SHOWNORMAL showCmd = win32con.SW_HIDE lpVerb = 'runas' # causes UAC elevation prompt. # print "Running", cmd, params # ShellExecute() doesn't seem to allow us to fetch the PID or handle # of the process, so we can't get anything useful from it. Therefore # the more complex ShellExecuteEx() must be used. # procHandle = win32api.ShellExecute(0, lpVerb, cmd, params, cmdDir, showCmd) procInfo = ShellExecuteEx(nShow=showCmd, fMask=shellcon.SEE_MASK_NOCLOSEPROCESS, lpVerb=lpVerb, lpFile=cmd, lpParameters=params) if wait: procHandle = procInfo['hProcess'] obj = win32event.WaitForSingleObject(procHandle, win32event.INFINITE) rc = win32process.GetExitCodeProcess(procHandle) # print "Process handle %s returned code %s" % (procHandle, rc) else: rc = None return rc
Example #3
Source File: win32.py From opsbro with MIT License | 6 votes |
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 #4
Source File: win32.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
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: document.py From ironpython2 with Apache License 2.0 | 6 votes |
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 #6
Source File: TraceCollector.py From ironpython2 with Apache License 2.0 | 6 votes |
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 #7
Source File: test.py From ironpython2 with Apache License 2.0 | 6 votes |
def run(self): last_time = os.stat(self.filename)[stat.ST_MTIME] while 1: try: rc = win32event.WaitForSingleObject(self.handle, win32event.INFINITE) win32file.FindNextChangeNotification(self.handle) except win32event.error, details: # handle closed - thread should terminate. if details[0] != winerror.ERROR_INVALID_HANDLE: raise break this_time = os.stat(self.filename)[stat.ST_MTIME] if this_time != last_time: print "Detected file change - flagging for reload." self.change_detected = True last_time = this_time
Example #8
Source File: advanced.py From ironpython2 with Apache License 2.0 | 6 votes |
def run(self): last_time = os.stat(self.filename)[stat.ST_MTIME] while 1: try: rc = win32event.WaitForSingleObject(self.handle, win32event.INFINITE) win32file.FindNextChangeNotification(self.handle) except win32event.error, details: # handle closed - thread should terminate. if details[0] != winerror.ERROR_INVALID_HANDLE: raise break this_time = os.stat(self.filename)[stat.ST_MTIME] if this_time != last_time: print "Detected file change - flagging for reload." self.change_detected = True last_time = this_time
Example #9
Source File: win32.py From Tautulli with GNU General Public License v3.0 | 6 votes |
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 #10
Source File: win32.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
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 #11
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 6 votes |
def Transmit(self, transmitData): """ This will be called to detect available IR Blasters. """ if not self.file: if not self.connecting: self.Connect() else: return False while self.receiving: time.sleep(0.05) writeOvlap = win32file.OVERLAPPED() writeOvlap.hEvent = win32event.CreateEvent(None, 0, 0, None) win32file.WriteFile(self.file, transmitData, writeOvlap) win32event.WaitForSingleObject(writeOvlap.hEvent, win32event.INFINITE) return True
Example #12
Source File: winpexpect.py From camr with GNU General Public License v2.0 | 5 votes |
def wait(self, timeout=None): """Wait until the child exits. If timeout is not specified this blocks indefinately. Otherwise, timeout specifies the number of seconds to wait.""" if self.exitstatus is not None: return if timeout is None: timeout = INFINITE else: timeout = 1000 * timeout ret = WaitForSingleObject(self.child_handle, timeout) if ret == WAIT_TIMEOUT: raise TIMEOUT, 'Timeout exceeded in wait().' self.exitstatus = GetExitCodeProcess(self.child_handle) return self.exitstatus
Example #13
Source File: __subprocess.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def wait(self): """Wait for child process to terminate. Returns returncode attribute.""" if self.returncode is None: obj = WaitForSingleObject(self._handle, INFINITE) self.returncode = GetExitCodeProcess(self._handle) return self.returncode
Example #14
Source File: process_waiter.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def processEnded(self, processHandle, processHandleKey): wfmoThread = self.phandleKeyToThreadHandle[processHandleKey] processTransport = self.phandleToTransport[processHandle] self.threadToNumEnded[wfmoThread] += 1 # Decrement proc handle count for thread self.threadToNumProcessHandles[wfmoThread] -= 1 # If we go from 63 to 62 phandles for the thread, mark it available. if self.threadToNumProcessHandles[wfmoThread] == 62: self.availableThreads.append(wfmoThread) self.usedThreads.remove(wfmoThread) # If we go to 0 phandles, end the thread elif self.threadToNumProcessHandles[wfmoThread] == 0: # Mark thread as unavailable self.availableThreads.remove(wfmoThread) # Notify the thread that it should exit. if not self.threadToMsgWindowCreated[wfmoThread]: val = WaitForSingleObject(self.threadToMsgWindowCreationEvent[wfmoThread], INFINITE) if val != WAIT_OBJECT_0: raise RuntimeError("WaitForSingleObject returned %d. It should only return %d" % (val, WAIT_OBJECT_0)) # Notify the thread that it should wait on the process handle. win32api.PostMessage( self.threadToMsgWindow[wfmoThread], # thread id WM_CLOSE_THREAD, # message 0, # wParam 0 # lParam ) # Cleanup thread resources del self.threadToNumProcessHandles[wfmoThread] del self.threadToMsgWindowCreated[wfmoThread] #del self.wfmoThread # Cleanup process handle resources del self.needWaiting[processHandleKey] del self.phandleToTransport[processHandle] # Call the transport's processEnded method processTransport.processEnded()
Example #15
Source File: process_waiter.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def notifyOnExit(self, processHandle, processTransport): processHandleKey = self.phandleToPhandleKey[processHandle] # If there are available threads, use one of them if len(self.availableThreads) > 0: wfmoThread = self.availableThreads[0] self.threadToNumProcessHandles[wfmoThread] += 1 self.phandleKeyToThreadHandle[processHandleKey] = wfmoThread # Update used/available thread lists if self.threadToNumProcessHandles[wfmoThread] == 63: self.usedThreads.append(wfmoThread) self.availableThreads.remove(wfmoThread) # Make sure the message window has been created so # we can send messages to the thread. if self.threadToMsgWindowCreated[wfmoThread] is False: val = WaitForSingleObject(self.threadToMsgWindowCreationEvent[wfmoThread], INFINITE) if val != WAIT_OBJECT_0: raise RuntimeError("WaitForSingleObject returned %d. It should only return %d" % (val, WAIT_OBJECT_0)) # Notify the thread that it should wait on the process handle. if win32api.PostMessage( self.threadToMsgWindow[wfmoThread], WM_NEW_PHANDLE, # message processHandleKey, # wParam 0 # lParam ) == 0: raise Exception("Failed to post thread message!") else: # Create a new thread and wait on the proc handle wfmoThread = threading.Thread( target=self.doWaitForProcessExit, args=(processHandleKey,), name="iocpreactor.process_waiter.ProcessWaiter.waitForProcessExit pid=%d" % self.realPid) # Create a window creation event that will be triggered from the thread self.threadToMsgWindowCreationEvent[wfmoThread] = CreateEvent(None, 0, 0, None) self.threadToMsgWindowCreated[wfmoThread] = False self.threadToNumProcessHandles[wfmoThread] = 1 self.availableThreads.append(wfmoThread) self.phandleKeyToThreadHandle[processHandleKey] = wfmoThread wfmoThread.start()
Example #16
Source File: IPC.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def stop(self): if self.master: r = win32event.WaitForSingleObject(self.mutex, win32event.INFINITE) filename = self._get_sic_path() try: os.remove(filename) except OSError, e: # print, but continue traceback.print_exc() self.master = 0 win32event.ReleaseMutex(self.mutex) # close it so the named mutex goes away win32api.CloseHandle(self.mutex) self.mutex = None
Example #17
Source File: subprocess.py From medicare-demo with Apache License 2.0 | 5 votes |
def wait(self): """Wait for child process to terminate. Returns returncode attribute.""" if self.returncode is None: obj = WaitForSingleObject(self._handle, INFINITE) self.returncode = GetExitCodeProcess(self._handle) return self.returncode
Example #18
Source File: _scons_subprocess.py From sitoa with Apache License 2.0 | 5 votes |
def wait(self): """Wait for child process to terminate. Returns returncode attribute.""" if self.returncode is None: obj = WaitForSingleObject(self._handle, INFINITE) self.returncode = GetExitCodeProcess(self._handle) return self.returncode
Example #19
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def ChangeReceiveMode(self, mode): """ This will be called to detect available IR Blasters. """ if not(mode == "l" or mode == "n"): return False#needs to be normal or learn if not self.file: return False writeOvlap = win32file.OVERLAPPED() writeOvlap.hEvent = win32event.CreateEvent(None, 0, 0, None) win32file.WriteFile(self.file, mode, writeOvlap) win32event.WaitForSingleObject(writeOvlap.hEvent, win32event.INFINITE) return True
Example #20
Source File: service_win32.py From mamonsu with BSD 3-Clause "New" or "Revised" License | 5 votes |
def SvcDoRun(self): # __file__ == 'service_win32.py' exe_dir = os.path.dirname(os.path.dirname(__file__)) os.chdir(exe_dir) win32evtlogutil.ReportEvent( self._svc_name_, servicemanager.PYS_SERVICE_STARTED, 0, servicemanager.EVENTLOG_INFORMATION_TYPE, (self._svc_name_, '')) config_file = os.path.join(exe_dir, 'agent.conf') config = Config(config_file) supervisor = Supervisor(config) win32evtlogutil.ReportEvent( self._svc_name_, servicemanager.PYS_SERVICE_STOPPED, 0, servicemanager.EVENTLOG_INFORMATION_TYPE, (self._svc_name_, '')) thread = Thread(target=supervisor.start) thread.daemon = True thread.start() while True: rc = win32event.WaitForSingleObject( self.hWaitStop, win32event.INFINITE) if rc == win32event.WAIT_OBJECT_0: win32evtlogutil.ReportEvent( self._svc_name_, servicemanager.PYS_SERVICE_STOPPED, 0, servicemanager.EVENTLOG_INFORMATION_TYPE, (self._svc_name_, '')) break
Example #21
Source File: platform_windows.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def SvcDoRun(self): self.ReportServiceStatus(win32service.SERVICE_START_PENDING) try: self.ReportServiceStatus(win32service.SERVICE_RUNNING) self.log("Starting service") self.start() win32event.WaitForSingleObject(self._stop_event, win32event.INFINITE) except Exception as e: self.error( "Error, causing Windows Service to exit early %s" % six.text_type(e) ) self.SvcStop()
Example #22
Source File: subprocess_hack.py From advanced-launcher with GNU General Public License v2.0 | 5 votes |
def wait(self): """Wait for child process to terminate. Returns returncode attribute.""" if self.returncode == None: obj = WaitForSingleObject(self._handle, INFINITE) self.returncode = GetExitCodeProcess(self._handle) _active.remove(self) return self.returncode
Example #23
Source File: _scons_subprocess.py From pivy with ISC License | 5 votes |
def wait(self): """Wait for child process to terminate. Returns returncode attribute.""" if self.returncode is None: obj = WaitForSingleObject(self._handle, INFINITE) self.returncode = GetExitCodeProcess(self._handle) return self.returncode
Example #24
Source File: _scons_subprocess.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def wait(self): """Wait for child process to terminate. Returns returncode attribute.""" if self.returncode is None: obj = WaitForSingleObject(self._handle, INFINITE) self.returncode = GetExitCodeProcess(self._handle) return self.returncode
Example #25
Source File: test_win32file.py From ironpython2 with Apache License 2.0 | 5 votes |
def testCompletionPortsQueued(self): class Foo: pass io_req_port = win32file.CreateIoCompletionPort(-1, None, 0, 0) overlapped = pywintypes.OVERLAPPED() overlapped.object = Foo() win32file.PostQueuedCompletionStatus(io_req_port, 0, 99, overlapped) errCode, bytes, key, overlapped = \ win32file.GetQueuedCompletionStatus(io_req_port, win32event.INFINITE) self.failUnlessEqual(errCode, 0) self.failUnless(isinstance(overlapped.object, Foo))
Example #26
Source File: test_win32file.py From ironpython2 with Apache License 2.0 | 5 votes |
def testSimpleOverlapped(self): # Create a file in the %TEMP% directory. import win32event testName = os.path.join( win32api.GetTempPath(), "win32filetest.dat" ) desiredAccess = win32file.GENERIC_WRITE overlapped = pywintypes.OVERLAPPED() evt = win32event.CreateEvent(None, 0, 0, None) overlapped.hEvent = evt # Create the file and write shit-loads of data to it. h = win32file.CreateFile( testName, desiredAccess, 0, None, win32file.CREATE_ALWAYS, 0, 0) chunk_data = str2bytes("z") * 0x8000 num_loops = 512 expected_size = num_loops * len(chunk_data) for i in range(num_loops): win32file.WriteFile(h, chunk_data, overlapped) win32event.WaitForSingleObject(overlapped.hEvent, win32event.INFINITE) overlapped.Offset = overlapped.Offset + len(chunk_data) h.Close() # Now read the data back overlapped overlapped = pywintypes.OVERLAPPED() evt = win32event.CreateEvent(None, 0, 0, None) overlapped.hEvent = evt desiredAccess = win32file.GENERIC_READ h = win32file.CreateFile( testName, desiredAccess, 0, None, win32file.OPEN_EXISTING, 0, 0) buffer = win32file.AllocateReadBuffer(0xFFFF) while 1: try: hr, data = win32file.ReadFile(h, buffer, overlapped) win32event.WaitForSingleObject(overlapped.hEvent, win32event.INFINITE) overlapped.Offset = overlapped.Offset + len(data) if not data is buffer: self.fail("Unexpected result from ReadFile - should be the same buffer we passed it") except win32api.error: break h.Close()
Example #27
Source File: test_win32trace.py From ironpython2 with Apache License 2.0 | 5 votes |
def join(self): win32event.WaitForSingleObject(self.processHandle, win32event.INFINITE) self.exitCode = win32process.GetExitCodeProcess(self.processHandle)
Example #28
Source File: serviceEvents.py From ironpython2 with Apache License 2.0 | 5 votes |
def SvcDoRun(self): # do nothing at all - just wait to be stopped win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE) # Write a stop message. servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STOPPED, (self._svc_name_, '') )
Example #29
Source File: threaded_extension.py From ironpython2 with Apache License 2.0 | 5 votes |
def run(self): self.running = True while self.running: errCode, bytes, key, overlapped = \ GetQueuedCompletionStatus(self.io_req_port, INFINITE) if key == ISAPI_SHUTDOWN and overlapped is None: break # Let the parent extension handle the command. dispatcher = self.extension.dispatch_map.get(key) if dispatcher is None: raise RuntimeError("Bad request '%s'" % (key,)) dispatcher(errCode, bytes, key, overlapped)
Example #30
Source File: tun-ping-responder.py From pyvpn with The Unlicense | 5 votes |
def transmit(self,dataToTransmit): # convert to string dataToTransmit = ''.join([chr(b) for b in dataToTransmit]) # write over tuntap interface win32file.WriteFile(self.tuntap, dataToTransmit, self.overlappedTx) win32event.WaitForSingleObject(self.overlappedTx.hEvent, win32event.INFINITE) self.overlappedTx.Offset = self.overlappedTx.Offset + len(dataToTransmit) #======================== private =========================================