當前位置: 首頁>>代碼示例>>Python>>正文


Python win32event.CreateEvent方法代碼示例

本文整理匯總了Python中win32event.CreateEvent方法的典型用法代碼示例。如果您正苦於以下問題:Python win32event.CreateEvent方法的具體用法?Python win32event.CreateEvent怎麽用?Python win32event.CreateEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在win32event的用法示例。


在下文中一共展示了win32event.CreateEvent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def __init__(self,tuntap,transmit):
    
        # store params
        self.tuntap               = tuntap
        self.transmit             = transmit
        
        # local variables
        self.goOn                 = True
        self.overlappedRx         = pywintypes.OVERLAPPED()
        self.overlappedRx.hEvent  = win32event.CreateEvent(None, 0, 0, None)
        
        # initialize parent
        threading.Thread.__init__(self)
        
        # give this thread a name
        self.name                 = 'readThread' 
開發者ID:alexsunday,項目名稱:pyvpn,代碼行數:18,代碼來源:tun-ping-responder.py

示例2: testNotifyChange

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def testNotifyChange(self):
        def change():
            hkey = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER, self.key_name)
            try:
                win32api.RegSetValue(hkey, None, win32con.REG_SZ, "foo")
            finally:
                win32api.RegDeleteKey(win32con.HKEY_CURRENT_USER, self.key_name)

        evt = win32event.CreateEvent(None,0,0,None)
        ## REG_NOTIFY_CHANGE_LAST_SET - values
        ## REG_CHANGE_NOTIFY_NAME - keys
        ## REG_NOTIFY_CHANGE_SECURITY - security descriptor
        ## REG_NOTIFY_CHANGE_ATTRIBUTES
        win32api.RegNotifyChangeKeyValue(win32con.HKEY_CURRENT_USER,1,win32api.REG_NOTIFY_CHANGE_LAST_SET,evt,True)
        ret_code=win32event.WaitForSingleObject(evt,0)
        # Should be no change.
        self.failUnless(ret_code==win32con.WAIT_TIMEOUT)
        change()
        # Our event should now be in a signalled state.
        ret_code=win32event.WaitForSingleObject(evt,0)
        self.failUnless(ret_code==win32con.WAIT_OBJECT_0) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:23,代碼來源:test_win32api.py

示例3: testCleanup1

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def testCleanup1(self):
        # We used to clobber all outstanding exceptions.
        def f1(invalidate):
            import win32event
            h = win32event.CreateEvent(None, 0, 0, None)
            if invalidate:
                win32api.CloseHandle(int(h))
            1/0
            # If we invalidated, then the object destruction code will attempt 
            # to close an invalid handle.  We don't wan't an exception in 
            # this case

        def f2(invalidate):
            """ This function should throw an IOError. """
            try:
                f1(invalidate)
            except ZeroDivisionError, exc:
                raise IOError("raise 2") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:handles.py

示例4: test_connect_with_payload

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def test_connect_with_payload(self):
        giveup_event = win32event.CreateEvent(None, 0, 0, None)
        t = threading.Thread(target=self.connect_thread_runner,
                             args=(True, giveup_event))
        t.start()
        time.sleep(0.1)
        s2 = socket.socket()
        ol = pywintypes.OVERLAPPED()
        s2.bind(('0.0.0.0', 0)) # connectex requires the socket be bound beforehand
        try:
            win32file.ConnectEx(s2, self.addr, ol, str2bytes("some expected request"))
        except win32file.error, exc:
            win32event.SetEvent(giveup_event)
            if exc.winerror == 10022: # WSAEINVAL
                raise TestSkipped("ConnectEx is not available on this platform")
            raise # some error error we don't expect. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_win32file.py

示例5: test_connect_without_payload

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def test_connect_without_payload(self):
        giveup_event = win32event.CreateEvent(None, 0, 0, None)
        t = threading.Thread(target=self.connect_thread_runner,
                             args=(False, giveup_event))
        t.start()
        time.sleep(0.1)
        s2 = socket.socket()
        ol = pywintypes.OVERLAPPED()
        s2.bind(('0.0.0.0', 0)) # connectex requires the socket be bound beforehand
        try:
            win32file.ConnectEx(s2, self.addr, ol)
        except win32file.error, exc:
            win32event.SetEvent(giveup_event)
            if exc.winerror == 10022: # WSAEINVAL
                raise TestSkipped("ConnectEx is not available on this platform")
            raise # some error error we don't expect. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_win32file.py

示例6: BeginThreadsSimpleMarshal

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def BeginThreadsSimpleMarshal(self, numThreads):
        """Creates multiple threads using simple (but slower) marshalling.
    
        Single interpreter object, but a new stream is created per thread.
    
        Returns the handles the threads will set when complete.
        """
        interp = win32com.client.Dispatch("Python.Interpreter")
        events = []
        threads = []
        for i in range(numThreads):
            hEvent = win32event.CreateEvent(None, 0, 0, None)
            events.append(hEvent)
            interpStream = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch, interp._oleobj_)
            t = threading.Thread(target=self._testInterpInThread, args=(hEvent, interpStream))
            t.setDaemon(1) # so errors dont cause shutdown hang
            t.start()
            threads.append(t)
        interp = None
        return threads, events

    #
    # NOTE - this doesnt quite work - Im not even sure it should, but Greg reckons
    # you should be able to avoid the marshal per thread!
    # I think that refers to CoMarshalInterface though... 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:testMarshal.py

示例7: BeginThreadsFastMarshal

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def BeginThreadsFastMarshal(self, numThreads):
        """Creates multiple threads using fast (but complex) marshalling.
    
        The marshal stream is created once, and each thread uses the same stream
    
        Returns the handles the threads will set when complete.
        """
        interp = win32com.client.Dispatch("Python.Interpreter")
        if freeThreaded:
            interp = pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch, interp._oleobj_)
        events = []
        threads = []
        for i in range(numThreads):
            hEvent = win32event.CreateEvent(None, 0, 0, None)
            t = threading.Thread(target=self._testInterpInThread, args=(hEvent, interp))
            t.setDaemon(1) # so errors dont cause shutdown hang
            t.start()
            events.append(hEvent)
            threads.append(t)
        return threads, events 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:testMarshal.py

示例8: __init__

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def __init__(self, filename):
        self._hfile = win32file.CreateFile(filename,
                                           win32con.GENERIC_READ | win32con.GENERIC_WRITE,
                                           win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
                                           win32security.SECURITY_ATTRIBUTES(),
                                           win32con.OPEN_EXISTING,
                                           win32con.FILE_FLAG_OVERLAPPED,
                                           0)
        self._read_ovrlpd = pywintypes.OVERLAPPED()
        self._read_ovrlpd.hEvent = win32event.CreateEvent(None, True,
                                                          False, None)
        self._write_ovrlpd = pywintypes.OVERLAPPED()
        self._write_ovrlpd.hEvent = win32event.CreateEvent(None, True,
                                                           False, None)
        self._bufs = []
        self._n = 0 
開發者ID:avocado-framework,項目名稱:avocado-vt,代碼行數:18,代碼來源:windows_support.py

示例9: test_addEvent

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def test_addEvent(self):
        """
        When an event which has been added to the reactor is set, the action
        associated with the event is invoked in the reactor thread.
        """
        reactorThreadID = getThreadID()
        reactor = self.buildReactor()
        event = win32event.CreateEvent(None, False, False, None)
        finished = Deferred()
        finished.addCallback(lambda ignored: reactor.stop())
        listener = Listener(finished)
        reactor.addEvent(event, listener, 'occurred')
        reactor.callWhenRunning(win32event.SetEvent, event)
        self.runReactor(reactor)
        self.assertTrue(listener.success)
        self.assertEqual(reactorThreadID, listener.logThreadID)
        self.assertEqual(reactorThreadID, listener.eventThreadID) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:test_win32events.py

示例10: test_ioThreadDoesNotChange

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def test_ioThreadDoesNotChange(self):
        """
        Using L{IReactorWin32Events.addEvent} does not change which thread is
        reported as the I/O thread.
        """
        results = []
        def check(ignored):
            results.append(isInIOThread())
            reactor.stop()
        reactor = self.buildReactor()
        event = win32event.CreateEvent(None, False, False, None)
        finished = Deferred()
        listener = Listener(finished)
        finished.addCallback(check)
        reactor.addEvent(event, listener, 'occurred')
        reactor.callWhenRunning(win32event.SetEvent, event)
        self.runReactor(reactor)
        self.assertTrue(listener.success)
        self.assertEqual([True], results) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:21,代碼來源:test_win32events.py

示例11: test_disconnectedOnError

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def test_disconnectedOnError(self):
        """
        If the event handler raises an exception, the event is removed from the
        reactor and the handler's C{connectionLost} method is called in the I/O
        thread and the exception is logged.
        """
        reactorThreadID = getThreadID()
        reactor = self.buildReactor()
        event = win32event.CreateEvent(None, False, False, None)

        result = []
        finished = Deferred()
        finished.addBoth(result.append)
        finished.addBoth(lambda ignored: reactor.stop())

        listener = Listener(finished)
        reactor.addEvent(event, listener, 'brokenOccurred')
        reactor.callWhenRunning(win32event.SetEvent, event)
        self.runReactor(reactor)

        self.assertIsInstance(result[0], Failure)
        result[0].trap(RuntimeError)

        self.assertEqual(reactorThreadID, listener.connLostThreadID)
        self.assertEqual(1, len(self.flushLoggedErrors(RuntimeError))) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:27,代碼來源:test_win32events.py

示例12: subscribe_and_yield_events

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def subscribe_and_yield_events(channel, query="*"):
    #SUBSCRIBE
    h = win32event.CreateEvent(None, 0, 0, None)
    s = win32evtlog.EvtSubscribe(channel, win32evtlog.EvtSubscribeToFutureEvents, SignalEvent=h, Query=query)

    #LOOP
    while True:
        while True:
            events = win32evtlog.EvtNext(s, 10)

            if len(events) == 0:
                break
            for event in events:
                raw_xml = win32evtlog.EvtRender(event, win32evtlog.EvtRenderEventXml)
                er = LogEvent(raw_xml, source_os=detect_current_os())
                if er.is_valid():
                    yield er
                else:
                    print("[ERROR] Parsing error")

        while True:
            #print('waiting...')
            w = win32event.WaitForSingleObjectEx(h, 200, True)
            if w == win32con.WAIT_OBJECT_0:
                break 
開發者ID:yarox24,項目名稱:attack_monitor,代碼行數:27,代碼來源:evtx_subscriber.py

示例13: send_startup_event

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def send_startup_event():
    if sys.platform == 'win32':
        try:
            import win32event
            import win32api
        except:
            return

        try:
            if DEBUG:
                log('bg::send_startup_event')
            startupEvent = win32event.CreateEvent(None, 0, 0, 'startupEvent')
            win32event.SetEvent(startupEvent)
            win32api.CloseHandle(startupEvent)
            if DEBUG:
                log('bg::send_startup_event: done')
        except:
            log_exc() 
開發者ID:alesnav,項目名稱:p2ptv-pi,代碼行數:20,代碼來源:BackgroundProcess.py

示例14: __init__

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def __init__(self, path):
        if not isinstance(path, basestring):
            raise TypeError("Path argument must be a basestring; instead"
                            " received %r" % (path,))
        self.path = path
        self.handle = win32file.CreateFile(
             self.path,
             0x0001,  # FILE_LIST_DIRECTORY
             win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
             None,
             win32con.OPEN_EXISTING,
             win32con.FILE_FLAG_BACKUP_SEMANTICS | win32con.FILE_FLAG_OVERLAPPED,
             None,
            )
        self.overlapped = win32file.OVERLAPPED()
        self.overlapped.hEvent = win32event.CreateEvent(None, True, 0, None) 
開發者ID:t4ngo,項目名稱:dragonfly,代碼行數:18,代碼來源:dirmon.py

示例15: test_addEvent

# 需要導入模塊: import win32event [as 別名]
# 或者: from win32event import CreateEvent [as 別名]
def test_addEvent(self):
        """
        When an event which has been added to the reactor is set, the action
        associated with the event is invoked.
        """
        reactor = self.buildReactor()
        event = win32event.CreateEvent(None, False, False, None)
        class Listener(object):
            success = False

            def logPrefix(self):
                return 'Listener'

            def occurred(self):
                self.success = True
                reactor.stop()

        listener = Listener()
        reactor.addEvent(event, listener, 'occurred')
        reactor.callWhenRunning(win32event.SetEvent, event)
        self.runReactor(reactor)
        self.assertTrue(listener.success) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:24,代碼來源:test_win32events.py


注:本文中的win32event.CreateEvent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。