Python win32event.WAIT_OBJECT_0 Examples

The following are 30 code examples of win32event.WAIT_OBJECT_0(). 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 vote down vote up
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: 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: subprocess.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def poll(self, _deadstate=None):
            """Check if child process has terminated.  Returns returncode
            attribute."""
            if self.returncode is None:
                if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0:
                    self.returncode = GetExitCodeProcess(self._handle)
            return self.returncode 
Example #5
Source File: subprocess_hack.py    From advanced-launcher with GNU General Public License v2.0 5 votes vote down vote up
def poll(self):
            """Check if child process has terminated.  Returns returncode
            attribute."""
            if self.returncode == None:
                if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0:
                    self.returncode = GetExitCodeProcess(self._handle)
                    _active.remove(self)
            return self.returncode 
Example #6
Source File: socketserverservice.py    From execnet with MIT License 5 votes vote down vote up
def SvcDoRun(self):
        # Redirect stdout and stderr to prevent "IOError: [Errno 9]
        # Bad file descriptor". Windows services don't have functional
        # output streams.
        sys.stdout = sys.stderr = open("nul", "w")

        # Write a 'started' event to the event log...
        win32evtlogutil.ReportEvent(
            self._svc_display_name_,
            servicemanager.PYS_SERVICE_STARTED,
            0,  # category
            servicemanager.EVENTLOG_INFORMATION_TYPE,
            (self._svc_name_, ""),
        )
        print("Begin: %s" % self._svc_display_name_)

        hostport = ":8888"
        print("Starting py.execnet SocketServer on %s" % hostport)
        serversock = socketserver.bind_and_listen(hostport)
        thread = threading.Thread(
            target=socketserver.startserver, args=(serversock,), kwargs={"loop": True}
        )
        thread.setDaemon(True)
        thread.start()

        # wait to be stopped or self.WAIT_TIME to pass
        while True:
            result = win32event.WaitForSingleObject(self.hWaitStop, self.WAIT_TIME)
            if result == win32event.WAIT_OBJECT_0:
                break

        # write a 'stopped' event to the event log.
        win32evtlogutil.ReportEvent(
            self._svc_display_name_,
            servicemanager.PYS_SERVICE_STOPPED,
            0,  # category
            servicemanager.EVENTLOG_INFORMATION_TYPE,
            (self._svc_name_, ""),
        )
        print("End: %s" % appname) 
Example #7
Source File: service_win32.py    From mamonsu with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #8
Source File: windows_service.py    From opsbro with MIT License 5 votes vote down vote up
def __check_for_hWaitStop(self):
        while True:
            rc = None
            # if the stop event hasn't been fired keep looping
            while rc != win32event.WAIT_OBJECT_0:
                # block for 100ms and listen for a stop event
                rc = win32event.WaitForSingleObject(self.hWaitStop, 100)
            # ok here we stop, warn the other parts about it
            stopper.do_stop('Stop from windows service') 
Example #9
Source File: _scons_subprocess.py    From sitoa with Apache License 2.0 5 votes vote down vote up
def poll(self, _deadstate=None):
            """Check if child process has terminated.  Returns returncode
            attribute."""
            if self.returncode is None:
                if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0:
                    self.returncode = GetExitCodeProcess(self._handle)
            return self.returncode 
Example #10
Source File: _dumbwin32proc.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def checkWork(self):
        if win32event.WaitForSingleObject(self.proc.hProcess, 0) != win32event.WAIT_OBJECT_0:
            return 0
        exitCode = win32process.GetExitCodeProcess(self.proc.hProcess)
        self.deactivate()
        self.proc.processEnded(exitCode)
        return 0 
Example #11
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 #12
Source File: _dumbwin32proc.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def checkWork(self):
        if win32event.WaitForSingleObject(self.proc.hProcess, 0) != win32event.WAIT_OBJECT_0:
            return 0
        exitCode = win32process.GetExitCodeProcess(self.proc.hProcess)
        self.deactivate()
        self.proc.processEnded(exitCode)
        return 0 
Example #13
Source File: _dumbwin32proc.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def checkWork(self):
        if win32event.WaitForSingleObject(self.proc.hProcess, 0) != win32event.WAIT_OBJECT_0:
            return 0
        exitCode = win32process.GetExitCodeProcess(self.proc.hProcess)
        if exitCode == 0:
            err = error.ProcessDone(exitCode)
        else:
            err = error.ProcessTerminated(exitCode)
        self.deactivate()
        self.proc.protocol.processEnded(failure.Failure(err))
        return 0 
Example #14
Source File: process_waiter.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
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 #15
Source File: process_waiter.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
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 #16
Source File: __subprocess.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 5 votes vote down vote up
def _internal_poll(self, _deadstate=None):
            """Check if child process has terminated.  Returns returncode
            attribute."""
            if self.returncode is None:
                if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0:
                    self.returncode = GetExitCodeProcess(self._handle)
            return self.returncode 
Example #17
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def GetDeviceInfo(self):
        """
        This will be called to detect IR device info.
        """
        if not self.file:
            return None
        writeOvlap = win32file.OVERLAPPED()
        writeOvlap.hEvent = win32event.CreateEvent(None, 0, 0, None)
        self.deviceInfoEvent = win32event.CreateEvent(None, 0, 0, None)
        win32file.WriteFile(self.file, "b".encode("ascii"), writeOvlap)
        if win32event.WaitForSingleObject(self.deviceInfoEvent, 250) == win32event.WAIT_OBJECT_0:
            return self.deviceInfo
        return None 
Example #18
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def TestIR(self):
        """
        This will be called to Transmit a known signal to verify blaster capability.
        """
        if not self.file:
            return None
        writeOvlap = win32file.OVERLAPPED()
        writeOvlap.hEvent = win32event.CreateEvent(None, 0, 0, None)
        self.deviceTestEvent = win32event.CreateEvent(None, 0, 0, None)
        win32file.WriteFile(self.file, "t".encode("ascii"), writeOvlap)
        if win32event.WaitForSingleObject(self.deviceTestEvent, 250) == win32event.WAIT_OBJECT_0:
            return True
        return None 
Example #19
Source File: _dumbwin32proc.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def checkWork(self):
        if win32event.WaitForSingleObject(self.proc.hProcess, 0) != win32event.WAIT_OBJECT_0:
            return 0
        exitCode = win32process.GetExitCodeProcess(self.proc.hProcess)
        self.deactivate()
        self.proc.processEnded(exitCode)
        return 0 
Example #20
Source File: _scons_subprocess.py    From pivy with ISC License 5 votes vote down vote up
def poll(self, _deadstate=None):
            """Check if child process has terminated.  Returns returncode
            attribute."""
            if self.returncode is None:
                if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0:
                    self.returncode = GetExitCodeProcess(self._handle)
            return self.returncode 
Example #21
Source File: _scons_subprocess.py    From web2board with GNU Lesser General Public License v3.0 5 votes vote down vote up
def poll(self, _deadstate=None):
            """Check if child process has terminated.  Returns returncode
            attribute."""
            if self.returncode is None:
                if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0:
                    self.returncode = GetExitCodeProcess(self._handle)
            return self.returncode 
Example #22
Source File: testMarshal.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _DoTestMarshal(self, fn, bCoWait = 0):
        #print "The main thread is %d" % (win32api.GetCurrentThreadId())
        threads, events = fn(2)
        numFinished = 0
        while 1:
            try:
                if bCoWait:
                    rc = pythoncom.CoWaitForMultipleHandles(0, 2000, events)
                else:
                    # Specifying "bWaitAll" here will wait for messages *and* all events
                    # (which is pretty useless)
                    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
        for t in threads:
            t.join(2)
            self.failIf(t.isAlive(), "thread failed to stop!?")
        threads = None # threads hold references to args
        # Seems to be a leak here I can't locate :(
        #self.failUnlessEqual(pythoncom._GetInterfaceCount(), 0)
        #self.failUnlessEqual(pythoncom._GetGatewayCount(), 0) 
Example #23
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 #24
Source File: test_win32file.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _watcherThreadOverlapped(self, dn, dh, changes):
        flags = win32con.FILE_NOTIFY_CHANGE_FILE_NAME
        buf = win32file.AllocateReadBuffer(8192)
        overlapped = pywintypes.OVERLAPPED()
        overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None)
        while 1:
            win32file.ReadDirectoryChangesW(dh,
                                            buf,
                                            False, #sub-tree
                                            flags,
                                            overlapped)
            # Wait for our event, or for 5 seconds.
            rc = win32event.WaitForSingleObject(overlapped.hEvent, 5000)
            if rc == win32event.WAIT_OBJECT_0:
                # got some data!  Must use GetOverlappedResult to find out
                # how much is valid!  0 generally means the handle has
                # been closed.  Blocking is OK here, as the event has
                # already been set.
                nbytes = win32file.GetOverlappedResult(dh, overlapped, True)
                if nbytes:
                    bits = win32file.FILE_NOTIFY_INFORMATION(buf, nbytes)
                    changes.extend(bits)
                else:
                    # This is "normal" exit - our 'tearDown' closes the
                    # handle.
                    # print "looks like dir handle was closed!"
                    return
            else:
                print "ERROR: Watcher thread timed-out!"
                return # kill the thread! 
Example #25
Source File: test_win32event.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testWaitableFire(self):
        h = win32event.CreateWaitableTimer(None, 0, None)
        dt = -160 # 160 ns.
        win32event.SetWaitableTimer(h, dt, 0, None, None, 0)
        rc = win32event.WaitForSingleObject(h, 1000)
        self.failUnlessEqual(rc, win32event.WAIT_OBJECT_0) 
Example #26
Source File: test_win32event.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testWaitableFireLong(self):
        h = win32event.CreateWaitableTimer(None, 0, None)
        dt = int2long(-160) # 160 ns.
        win32event.SetWaitableTimer(h, dt, 0, None, None, 0)
        rc = win32event.WaitForSingleObject(h, 1000)
        self.failUnlessEqual(rc, win32event.WAIT_OBJECT_0) 
Example #27
Source File: winprocess.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def kill(self, gracePeriod=5000):
        """
        Kill process. Try for an orderly shutdown via WM_CLOSE.  If
        still running after gracePeriod (5 sec. default), terminate.
        """
        win32gui.EnumWindows(self.__close__, 0)
        if self.wait(gracePeriod) != win32event.WAIT_OBJECT_0:
            win32process.TerminateProcess(self.hProcess, 0)
            win32api.Sleep(100) # wait for resources to be released 
Example #28
Source File: timer_demo.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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 #29
Source File: rastest.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def Connect(entryName, bUseCallback):
    if bUseCallback:
        theCallback = Callback
        win32event.ResetEvent(callbackEvent)
    else:
        theCallback = None
    #       in order to *use* the username/password of a particular dun entry, one must
    #       explicitly get those params under win95....
    try:
        dp, b = win32ras.GetEntryDialParams( None, entryName )
    except:
        print "Couldn't find DUN entry: %s" % entryName
    else:
        hras, rc = win32ras.Dial(None, None, (entryName, "", "", dp[ 3 ], dp[ 4 ], ""),theCallback)
    #       hras, rc = win32ras.Dial(None, None, (entryName, ),theCallback)
    #       print hras, rc
        if not bUseCallback and rc != 0:
            print "Could not dial the RAS connection:", win32ras.GetErrorString(rc)
            hras = HangUp( hras )
        #       don't wait here if there's no need to....
        elif bUseCallback and win32event.WaitForSingleObject(callbackEvent, 60000)!=win32event.WAIT_OBJECT_0:
            print "Gave up waiting for the process to complete!"
            #       sdk docs state one must explcitly hangup, even if there's an error....
            try:
                cs = win32ras.GetConnectStatus( hras )
            except:
                #       on error, attempt a hang up anyway....
                hras = HangUp( hras )
            else:
                if int( cs[ 0 ] ) == win32ras.RASCS_Disconnected:
                    hras = HangUp( hras )
    return hras, rc 
Example #30
Source File: subprocess24.py    From mishkal with GNU General Public License v3.0 5 votes vote down vote up
def poll(self):
            """Check if child process has terminated.  Returns returncode
            attribute."""
            if self.returncode == None:
                if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0:
                    self.returncode = GetExitCodeProcess(self._handle)
                    _active.remove(self)
            return self.returncode