Python win32event.CreateEvent() Examples
The following are 30
code examples of win32event.CreateEvent().
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: windows_support.py From avocado-vt with GNU General Public License v2.0 | 7 votes |
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
Example #2
Source File: SMWinservice.py From biometric-attendance-sync-tool with GNU General Public License v3.0 | 6 votes |
def __init__(self, args): ''' Constructor of the winservice ''' win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) socket.setdefaulttimeout(60)
Example #3
Source File: test_win32events.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #4
Source File: HID.py From EventGhost with GNU General Public License v2.0 | 6 votes |
def __init__(self, deviceName, devicePath, threadName = None): self.lockObject = threading.Lock() self.lockObject.acquire() self.handle = None self.text = Text self.deviceName = deviceName self.devicePath = devicePath self.abort = False self.initialized = False self._overlappedRead = win32file.OVERLAPPED() self._overlappedRead.hEvent = win32event.CreateEvent(None, 1, 0, None) self._overlappedWrite = None self.RawCallback = None self.ButtonCallback = None self.ValueCallback = None self.StopCallback = None threading.Thread.__init__(self, name = threadName if threadName else self.devicePath)
Example #5
Source File: test_win32api.py From ironpython2 with Apache License 2.0 | 6 votes |
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)
Example #6
Source File: handles.py From ironpython2 with Apache License 2.0 | 6 votes |
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")
Example #7
Source File: BackgroundProcess.py From p2ptv-pi with MIT License | 6 votes |
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()
Example #8
Source File: ABuWinUtil.py From abu with GNU General Public License v3.0 | 6 votes |
def socket_bind_recv(socket_fn, cmd_handler): """ 非bsd系统的进程间通信,接受消息,处理消息,使用windows全局共享内存实现, 函数名称保持与bsd的接口名称一致 :param socket_fn: 共享内存文件名称 :param cmd_handler: cmd处理函数,callable类型 """ if not callable(cmd_handler): print('socket_bind_recv cmd_handler must callable!') while True: global_fn = 'Global\\{}'.format(socket_fn) event = w32e.CreateEvent(None, 0, 0, global_fn) event_mmap = mmf.mmapfile(None, socket_fn, 1024) w32e.WaitForSingleObject(event, -1) socket_cmd = event_mmap.read(1024).decode() # 把接收到的socket传递给外部对应的处理函数 cmd_handler(socket_cmd) event_mmap.close() win_api.CloseHandle(event)
Example #9
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 #10
Source File: tun-ping-responder.py From pyvpn with The Unlicense | 6 votes |
def __init__(self,tuntap): # store params self.tuntap = tuntap # local variables self.goOn = True self.createIPv6 = False self.overlappedTx = pywintypes.OVERLAPPED() self.overlappedTx.hEvent = win32event.CreateEvent(None, 0, 0, None) # initialize parent threading.Thread.__init__(self) # give this thread a name self.name = 'writeThread'
Example #11
Source File: tun-ping-responder.py From pyvpn with The Unlicense | 6 votes |
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'
Example #12
Source File: dirmon.py From dragonfly with GNU Lesser General Public License v3.0 | 6 votes |
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)
Example #13
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 6 votes |
def __start__(self): global ptr_fmt global ptr_len self.info.eventPrefix = "MceRemote" if ptr_fmt == None: #Need to set this once per installation, depending on 32 or 64 bit OS from os import environ ptr_fmt = "i" #pack/unpack format for 32 bit int if environ.get("PROCESSOR_ARCHITECTURE") == "AMD64" or environ.get("PROCESSOR_ARCHITEW6432") == "AMD64": ptr_fmt = "q" #pack/unpack format for 64 bit int ptr_len = 8 self.hFinishedEvent = win32event.CreateEvent(None, 1, 0, None) try: self.remoteList = self.irDecoder.SetKeyMappingFromFile(self.__class__.__name__) except: pass self.client = MceMessageReceiver(self) self.msgThread = Thread(target=self.client) self.msgThread.start()
Example #14
Source File: test_win32events.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #15
Source File: evtx_subscriber.py From attack_monitor with GNU General Public License v3.0 | 6 votes |
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
Example #16
Source File: testMarshal.py From ironpython2 with Apache License 2.0 | 6 votes |
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
Example #17
Source File: testMarshal.py From ironpython2 with Apache License 2.0 | 6 votes |
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...
Example #18
Source File: test_win32file.py From ironpython2 with Apache License 2.0 | 6 votes |
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.
Example #19
Source File: test_win32file.py From ironpython2 with Apache License 2.0 | 6 votes |
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.
Example #20
Source File: test_win32events.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #21
Source File: test_win32events.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #22
Source File: test_win32events.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)))
Example #23
Source File: test_win32events.py From python-for-android with Apache License 2.0 | 6 votes |
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)
Example #24
Source File: test_win32events.py From learn_python3_spider with MIT License | 6 votes |
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)))
Example #25
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 6 votes |
def Stop(self): """ This will be called to stop the thread. """ if self.file: writeOvlap = win32file.OVERLAPPED() writeOvlap.hEvent = win32event.CreateEvent(None, 0, 0, None) msg = "q".encode("ascii") win32file.WriteFile(self.file, msg, writeOvlap) win32file.CloseHandle(self.file) self.file = None self.keepRunning = False if self.service: win32service.CloseServiceHandle(self.service) #eg.PrintNotice("MCE_Vista: stopping thread")
Example #26
Source File: test_win32events.py From learn_python3_spider with MIT License | 5 votes |
def test_notDisconnectedOnShutdown(self): """ Event handlers added with L{IReactorWin32Events.addEvent} do not have C{connectionLost} called on them if they are still active when the reactor shuts down. """ reactor = self.buildReactor() event = win32event.CreateEvent(None, False, False, None) finished = Deferred() listener = Listener(finished) reactor.addEvent(event, listener, 'occurred') reactor.callWhenRunning(reactor.stop) self.runReactor(reactor) self.assertIsNone(listener.connLostThreadID)
Example #27
Source File: Stateless_module.py From XFLTReaT with MIT License | 5 votes |
def post_authentication_server(self, control_message, additional_data): c = self.lookup_client_pub(additional_data) if c.get_initiated(): c.set_authenticated(True) self.packetselector.add_client(c) if c.get_pipe_r() not in self.rlist: self.rlist.append(c.get_pipe_r()) if self.os_type == common.OS_WINDOWS: # creating objects and adding to corresponding lists import win32event import win32file import pywintypes hEvent_pipe = win32event.CreateEvent(None, 0, 0, None) # for reading from the pipe overlapped_pipe = pywintypes.OVERLAPPED() overlapped_pipe.hEvent = hEvent_pipe message_buffer = win32file.AllocateReadBuffer(4096) self.olist.append(overlapped_pipe) self.elist.append(hEvent_pipe) self.mlist.append(message_buffer) self.ulist.append(len(self.elist)-1) return True return False # PLACEHOLDER: prolog for the communication # What comes here: anything that should be set up before the actual # communication
Example #28
Source File: _win32serialport.py From learn_python3_spider with MIT License | 5 votes |
def __init__(self, protocol, deviceNameOrPortNumber, reactor, baudrate = 9600, bytesize = EIGHTBITS, parity = PARITY_NONE, stopbits = STOPBITS_ONE, xonxoff = 0, rtscts = 0): self._serial = self._serialFactory( deviceNameOrPortNumber, baudrate=baudrate, bytesize=bytesize, parity=parity, stopbits=stopbits, timeout=None, xonxoff=xonxoff, rtscts=rtscts) self.flushInput() self.flushOutput() self.reactor = reactor self.protocol = protocol self.outQueue = [] self.closed = 0 self.closedNotifies = 0 self.writeInProgress = 0 self.protocol = protocol self._overlappedRead = win32file.OVERLAPPED() self._overlappedRead.hEvent = win32event.CreateEvent(None, 1, 0, None) self._overlappedWrite = win32file.OVERLAPPED() self._overlappedWrite.hEvent = win32event.CreateEvent(None, 0, 0, None) self.reactor.addEvent(self._overlappedRead.hEvent, self, 'serialReadEvent') self.reactor.addEvent(self._overlappedWrite.hEvent, self, 'serialWriteEvent') self.protocol.makeConnection(self) self._finishPortSetup()
Example #29
Source File: socketserverservice.py From execnet with MIT License | 5 votes |
def __init__(self, args): # The exe-file has messages for the Event Log Viewer. # Register the exe-file as event source. # # Probably it would be better if this is done at installation time, # so that it also could be removed if the service is uninstalled. # Unfortunately it cannot be done in the 'if __name__ == "__main__"' # block below, because the 'frozen' exe-file does not run this code. # win32evtlogutil.AddSourceToRegistry( self._svc_display_name_, servicemanager.__file__, "Application" ) win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self.WAIT_TIME = 1000 # in milliseconds
Example #30
Source File: platform_windows.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def __init__(self, *args): self.controller = None win32serviceutil.ServiceFramework.__init__(self, *args) self._stop_event = win32event.CreateEvent(None, 0, 0, None)