Python win32event.SetEvent() Examples
The following are 30
code examples of win32event.SetEvent().
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: 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 #2
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 #3
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 #4
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 #5
Source File: test_win32events.py From learn_python3_spider with MIT License | 6 votes |
def test_disconnectOnReturnValue(self): """ If the event handler returns a value, the event is removed from the reactor and the handler's C{connectionLost} method is called in the I/O thread. """ 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, 'returnValueOccurred') reactor.callWhenRunning(win32event.SetEvent, event) self.runReactor(reactor) self.assertIsInstance(result[0], Failure) result[0].trap(EnvironmentError) self.assertEqual(reactorThreadID, listener.connLostThreadID)
Example #6
Source File: test_win32events.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_disconnectOnReturnValue(self): """ If the event handler returns a value, the event is removed from the reactor and the handler's C{connectionLost} method is called in the I/O thread. """ 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, 'returnValueOccurred') reactor.callWhenRunning(win32event.SetEvent, event) self.runReactor(reactor) self.assertIsInstance(result[0], Failure) result[0].trap(EnvironmentError) self.assertEqual(reactorThreadID, listener.connLostThreadID)
Example #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
Source File: service_win32.py From mamonsu with BSD 3-Clause "New" or "Revised" License | 5 votes |
def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop)
Example #14
Source File: platform_windows.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def SvcStop(self): self.log("Stopping scalyr service") self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self._stop_event) self.controller.invoke_termination_handler() self.ReportServiceStatus(win32service.SERVICE_STOPPED)
Example #15
Source File: socketserverservice.py From execnet with MIT License | 5 votes |
def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop)
Example #16
Source File: ceajenkins.py From CityEnergyAnalyst with MIT License | 5 votes |
def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop) self._running = False
Example #17
Source File: windows_service.py From opsbro with MIT License | 5 votes |
def SvcStop(self): import servicemanager # tell windows SCM we're shutting down self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) servicemanager.LogInfoMsg("OpsBro Start") # launch the stop event win32event.SetEvent(self.hWaitStop)
Example #18
Source File: DaemonCmd.py From grease with MIT License | 5 votes |
def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop)
Example #19
Source File: ABuWinUtil.py From abu with GNU General Public License v3.0 | 5 votes |
def socket_send_msg(socket_fn, msg): """ 非bsd系统的进程间通信,发送消息,使用windows全局共享内存实现,函数名称保持与bsd的接口名称一致 :param socket_fn: : 共享内存名称 :param msg: 字符串类型需要传递的数据,不需要encode,内部进行encode """ global_fn = 'Global\\{}'.format(socket_fn) event = w32e.OpenEvent(w32e.EVENT_ALL_ACCESS, 0, global_fn) event_mmap = mmf.mmapfile(None, socket_fn, 1024) w32e.SetEvent(event) event_mmap.write(msg) event_mmap.close() win_api.CloseHandle(event)
Example #20
Source File: HID.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def AbortThread(self): self.abort = True if self._overlappedWrite: win32event.SetEvent(self._overlappedWrite.hEvent) win32event.SetEvent(self._overlappedRead.hEvent)
Example #21
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def __stop__(self): eg.PrintNotice("MCE_Vista: Stopping Mce Vista plugin") win32event.SetEvent(self.hFinishedEvent) self.client.Stop() self.client = None
Example #22
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def __stop__(self): if self.serial is not None: if self.receiveThread: win32event.SetEvent(self.stopEvent) self.receiveThread.join(1.0) self.serial.close() self.serial = None
Example #23
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def __stop__(self): if self.serial is not None: if self.receiveThread: win32event.SetEvent(self.stopEvent) self.receiveThread.join(1.0) self.serial.close() self.serial = None
Example #24
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def AbortThread(self): self.abort = True win32event.SetEvent(self._overlappedRead.hEvent) self.plugin.status = 2
Example #25
Source File: loglib.py From CVE-2016-6366 with MIT License | 5 votes |
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 #26
Source File: agent.py From Windows-Agent with Apache License 2.0 | 5 votes |
def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop) self.isAlive = False
Example #27
Source File: SMWinservice.py From biometric-attendance-sync-tool with GNU General Public License v3.0 | 5 votes |
def SvcStop(self): ''' Called when the service is asked to stop ''' self.stop() self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop)
Example #28
Source File: testMarshal.py From ironpython2 with Apache License 2.0 | 5 votes |
def _testInterpInThread(self, stopEvent, interp): try: self._doTestInThread(interp) finally: win32event.SetEvent(stopEvent)
Example #29
Source File: testGIT.py From ironpython2 with Apache License 2.0 | 5 votes |
def TestInterpInThread(stopEvent, cookie): try: DoTestInterpInThread(cookie) finally: win32event.SetEvent(stopEvent)
Example #30
Source File: eventsApartmentThreaded.py From ironpython2 with Apache License 2.0 | 5 votes |
def OnQuit(self): thread = win32api.GetCurrentThreadId() print "OnQuit event processed on thread %d"%thread win32event.SetEvent(self.event)