def __init__(self, args): print('init') win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self.isAlive = True self._poll_intvl = 30
def __init__(self, args): self.vbs = os.path.join(TGTDIR, 'vulnservice_task.vbs') self.timeout = 1000 * 60 win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self._running = True socket.setdefaulttimeout(60)
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) self.stop_event = win32event.CreateEvent(None, 0, 0, None) self.stop_requested = False
def get_new_event(sa=None, bManualReset=True, bInitialState=True, objectName=None): return win32event.CreateEvent(sa, bManualReset, bInitialState, objectName)
def __init__(self, args): '''Constructor of the winservice''' win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) socket.setdefaulttimeout(60)
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self.logger = self._getLogger() self.run = True
def __init__(self): self.h = win32event.CreateEvent(None, 0, 0, None) win32api.CloseHandle(int(self.h))
def __init__(self, port, #number of device, numbering starts at #zero. if everything fails, the user #can specify a device string, note #that this isn't portable anymore baudrate=9600, #baudrate bytesize=EIGHTBITS, #number of databits parity=PARITY_NONE, #enable parity checking stopbits=STOPBITS_ONE, #number of stopbits timeout=None, #set a timeout value, None for waiting forever xonxoff=0, #enable software flow control rtscts=0, #enable RTS/CTS flow control ): """initialize comm port""" self.timeout = timeout if type(port) == type(''): #strings are taken directly self.portstr = port else: self.portstr = 'COM%d' % (port+1) #numbers are transformed to a string #self.portstr = '\\\\.\\COM%d' % (port+1) #WIN NT format?? self.hComPort = win32file.CreateFile(self.portstr, win32con.GENERIC_READ | win32con.GENERIC_WRITE, 0, # exclusive access None, # no security win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL | win32con.FILE_FLAG_OVERLAPPED, None) # Setup a 4k buffer win32file.SetupComm(self.hComPort, 4096, 4096) #Save original timeout values: self.orgTimeouts = win32file.GetCommTimeouts(self.hComPort) #Set Windows timeout values #timeouts is a tuple with the following items: #(ReadIntervalTimeout,ReadTotalTimeoutMultiplier, # ReadTotalTimeoutConstant,WriteTotalTimeoutMultiplier, # WriteTotalTimeoutConstant) if timeout: timeouts = (timeout*1000, 0, timeout*1000, 0, 0) else: #timeouts = (win32con.MAXDWORD, 1, 0, 1, 0) timeouts = (win32con.MAXDWORD, 0, 0, 0, 1000) win32file.SetCommTimeouts(self.hComPort, timeouts) #win32file.SetCommMask(self.hComPort, win32file.EV_RXCHAR | win32file.EV_TXEMPTY | # win32file.EV_RXFLAG | win32file.EV_ERR) win32file.SetCommMask(self.hComPort, win32file.EV_RXCHAR | win32file.EV_RXFLAG | win32file.EV_ERR) #win32file.SetCommMask(self.hComPort, win32file.EV_ERR) # Setup the connection info. # Get state and modify it: comDCB = win32file.GetCommState(self.hComPort) comDCB.BaudRate = baudrate if bytesize == FIVEBITS: comDCB.ByteSize = 5 elif bytesize == SIXBITS: comDCB.ByteSize = 6 elif bytesize == SEVENBITS: comDCB.ByteSize = 7 elif bytesize == EIGHTBITS: comDCB.ByteSize = 8 if parity == PARITY_NONE: comDCB.Parity = win32file.NOPARITY comDCB.fParity = 0 # Dis/Enable Parity Check elif parity == PARITY_EVEN: comDCB.Parity = win32file.EVENPARITY comDCB.fParity = 1 # Dis/Enable Parity Check elif parity == PARITY_ODD: comDCB.Parity = win32file.ODDPARITY comDCB.fParity = 1 # Dis/Enable Parity Check if stopbits == STOPBITS_ONE: comDCB.StopBits = win32file.ONESTOPBIT elif stopbits == STOPBITS_TWO: comDCB.StopBits = win32file.TWOSTOPBITS comDCB.fBinary = 1 # Enable Binary Transmission # Char. w/ Parity-Err are replaced with 0xff (if fErrorChar is set to TRUE) if rtscts: comDCB.fRtsControl = win32file.RTS_CONTROL_HANDSHAKE comDCB.fDtrControl = win32file.DTR_CONTROL_HANDSHAKE else: comDCB.fRtsControl = win32file.RTS_CONTROL_ENABLE comDCB.fDtrControl = win32file.DTR_CONTROL_ENABLE comDCB.fOutxCtsFlow = rtscts comDCB.fOutxDsrFlow = rtscts comDCB.fOutX = xonxoff comDCB.fInX = xonxoff comDCB.fNull = 0 comDCB.fErrorChar = 0 comDCB.fAbortOnError = 0 win32file.SetCommState(self.hComPort, comDCB) # Clear buffers: # Remove anything that was there win32file.PurgeComm(self.hComPort, win32file.PURGE_TXCLEAR | win32file.PURGE_TXABORT | win32file.PURGE_RXCLEAR | win32file.PURGE_RXABORT) #print win32file.ClearCommError(self.hComPort) #flags, comState = self.overlapped = win32file.OVERLAPPED() self.overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None)
def __init__(self, *args): win32serviceutil.ServiceFramework.__init__(self, *args) self.log('init') self.stop_event = win32event.CreateEvent(None, 0, 0, None)
def f1(invalidate): import win32event h = win32event.CreateEvent(None, 0, 0, None) if invalidate: win32api.CloseHandle(int(h)) 1 / 0
def __init__(self, args): super().__init__(args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def __init__(self, *args): win32serviceutil.ServiceFramework.__init__(self, *args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) socket.setdefaulttimeout(5) self.stop_requested = False
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) self.updater = None self.stop_event_handle = win32event.CreateEvent(None, 0, 0, None) self.running = False
def __init__(self, args, bufsize=0, stdin=None, stdout=None, stderr=None, universal_newlines=False, close_fds=False, timeout_for_child_stream_duplication_event=30, **kwargs): if not isinstance(bufsize, int): raise TypeError("bufsize must be an integer") self.commandline_passed = {} self._cleanup_on_terminate = [] for s, p, m in [('stdin', stdin, 'w'), ('stdout', stdout, 'r'), ('stderr', stderr, 'r')]: if p is None: self.commandline_passed[s] = (None, 'null') elif p == subprocess.PIPE: if m == 'r': mode = 'rU' if universal_newlines else 'rb' else: mode = 'wb' piperead, pipewrite = os.pipe() myfile = os.fdopen(pipewrite if m == 'w' else piperead, mode, bufsize) childhandle = str( int( msvcrt.get_osfhandle(pipewrite if m == 'r' else piperead))) self._cleanup_on_terminate.append(pipewrite if m == 'r' else piperead) self.commandline_passed[s] = (myfile, childhandle, piperead, pipewrite) else: if isinstance(p, int): childhandle = msvcrt.get_osfhandle(stdin) else: # Assuming file-like object childhandle = msvcrt.get_osfhandle(p.fileno()) #The base implementation duplicates the handle, so we will too #It doesn't need to be inheritable for us, though cp = win32api.GetCurrentProcess() childhandle = win32api.DuplicateHandle( cp, childhandle, cp, 0, #desiredAccess ignored because of DUPLICATE_SAME_ACCESS 0, #Inheritable win32con.DUPLICATE_SAME_ACCESS) self.commandline_passed[s] = (None, str(int(childhandle)), childhandle, p) self._wait_for_child_duplication_event = win32event.CreateEvent( None, 1, #bManualReset 0, None) args += [ str(os.getpid()), str(int(self._wait_for_child_duplication_event)), self.commandline_passed['stdin'][1], self.commandline_passed['stdout'][1], self.commandline_passed['stderr'][1], ] super(HandlesOverCommandLinePopen, self).__init__(args, bufsize=bufsize, stdin=None, stdout=None, stderr=None, close_fds=close_fds, universal_newlines=universal_newlines, **kwargs) if timeout_for_child_stream_duplication_event: if not self.wait_for_child_stream_duplication_event( timeout_for_child_stream_duplication_event): logger.warning( "Timed out waiting for child process to duplicate its io streams" ) self.stdin = self.commandline_passed['stdin'][0] self.stdout = self.commandline_passed['stdout'][0] self.stderr = self.commandline_passed['stderr'][0]
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) CommonService.__init__(self) self._hWaitStop = win32event.CreateEvent(None, 1, 0, None) self._user = None
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) # create an event to listen for stop requests on self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) # create an event to listen for stop requests on self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self.home = r'C:\.freezer' self.insecure = False
def testMsgWaitForMultipleObjectsEx2(self): # test with non-empty list event = win32event.CreateEvent(None, 0, 0, None) res = win32event.MsgWaitForMultipleObjectsEx([event], 0, 0, 0) self.assertEquals(res, win32event.WAIT_TIMEOUT)
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) # Create an event which we will use to wait on. # The "service stop" request will set this event. self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self._engine = Engine(_getConfigPath())
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self.stop_requested = False self._old_excepthook = sys.excepthook
# Much of the code here contributed by Jethro Wright. import sys import os import win32ras # Build a little dictionary of RAS states to decent strings. # eg win32ras.RASCS_OpenPort -> "OpenPort" stateMap = {} for name, val in win32ras.__dict__.items(): if name[:6] == "RASCS_": stateMap[val] = name[6:] # Use a lock so the callback can tell the main thread when it is finished. import win32event callbackEvent = win32event.CreateEvent(None, 0, 0, None) def Callback(hras, msg, state, error, exterror): # print "Callback called with ", hras, msg, state, error, exterror stateName = stateMap.get(state, "Unknown state?") print "Status is %s (%04lx), error code is %d" % (stateName, state, error) finished = state in [win32ras.RASCS_Connected] if finished: win32event.SetEvent(callbackEvent) if error != 0 or int(state) == win32ras.RASCS_Disconnected: # we know for sure this is a good place to hangup.... print "Detected call failure: %s" % win32ras.GetErrorString(error) HangUp(hras) win32event.SetEvent(callbackEvent)
from win32com.server.util import wrap import pythoncom, sys, os, time, win32api, win32event, tempfile from win32com.bits import bits TIMEOUT = 200 # ms StopEvent = win32event.CreateEvent(None, 0, 0, None) job_name = 'bits-pywin32-test' states = dict([(val, (name[13:])) for name, val in vars(bits).items() if name.startswith('BG_JOB_STATE_')]) bcm = pythoncom.CoCreateInstance(bits.CLSID_BackgroundCopyManager, None, pythoncom.CLSCTX_LOCAL_SERVER, bits.IID_IBackgroundCopyManager) class BackgroundJobCallback: _com_interfaces_ = [bits.IID_IBackgroundCopyCallback] _public_methods_ = ["JobTransferred", "JobError", "JobModification"] def JobTransferred(self, job): print('Job Transferred', job) job.Complete() win32event.SetEvent(StopEvent) # exit msg pump def JobError(self, job, error): print('Job Error', job, error) f = error.GetFile()
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) # create an event that SvcDoRun can wait on and SvcStop # can set. self.stop_event = win32event.CreateEvent(None, 0, 0, None)
if type(arg) is dict: if globals is None: globals = arg elif locals is None: locals = arg else: raise Exception( "Exec can be called with at most 2 dictionary arguments" ) else: pass exec(stmt, globals, locals) idle_queue = [] idle_queue_event = win32event.CreateEvent(None, 0, 0, None) def add_idle_task(task): idle_queue.append(task) win32event.SetEvent(idle_queue_event) def serve(clsid="{506e67c3-55b5-48c3-a035-eed5deea7d6d}"): """Launch the COM server, clsid is the XLPython object class id """ clsid = pywintypes.IID(clsid) # Ovveride CreateInstance in default policy to instantiate the XLPython object --- BaseDefaultPolicy = win32com.server.policy.DefaultPolicy class MyPolicy(BaseDefaultPolicy):
def __init__(self, doc): self.doc = doc self.adminEvent = win32event.CreateEvent(None, 0, 0, None) self.stopEvent = win32event.CreateEvent(None, 0, 0, None) self.watchEvent = None pywin.mfc.thread.WinThread.__init__(self)
def __init__(self): # We reuse this event for all events. self.event = win32event.CreateEvent(None, 0, 0, None)
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def HandleData(self): """ This runs once a connection to the named pipe is made. It receives the ir data and passes it to the plugins IRDecoder. """ #if self.sentMessageOnce: # eg.PrintNotice("MCE_Vista: Connected to MceIr pipe, started handling IR events") # self.plugin.TriggerEvent("Connected") nMax = 2048 self.result = [] self.freqs = [0] self.readOvlap = win32file.OVERLAPPED() self.readOvlap.hEvent = win32event.CreateEvent(None, 0, 0, None) handles = [self.plugin.hFinishedEvent, self.readOvlap.hEvent] self.timeout = win32event.INFINITE while self.keepRunning: try: (hr, data) = win32file.ReadFile(self.file, nMax, self.readOvlap) except: win32file.CloseHandle(self.file) self.file = None break self.receivingTimeout = eg.scheduler.AddTask( 0.3, self.SetReceiving, False) rc = win32event.WaitForMultipleObjects(handles, False, self.timeout) self.SetReceiving(True) if rc == win32event.WAIT_OBJECT_0: #Finished event self.keepRunning = False break elif rc == win32event.WAIT_TIMEOUT: #Learn timeout #eg.PrintNotice("LearnTimeout: Sending ir code %s"%str(self.result)) self.learnDialog.GotCode(self.freqs, self.result) self.result = [] self.timeout = win32event.INFINITE rc = win32event.WaitForMultipleObjects(handles, False, self.timeout) if rc == win32event.WAIT_OBJECT_0: #Finished event self.keepRunning = False break try: nGot = self.readOvlap.InternalHigh if nGot == 0: continue if nGot % ptr_len == 1: #Query result, not ir code data if data[0] == "b".encode("ascii"): self.deviceInfo = unpack_from(6 * ptr_fmt, data[1:nGot]) win32event.SetEvent(self.deviceInfoEvent) elif data[0] == "t".encode("ascii"): win32event.SetEvent(self.deviceTestEvent) continue #pull of the header data while nGot > 0: header = unpack_from(3 * ptr_fmt, data) if header[0] == 1 and header[2] > 0: self.freqs.append(header[2]) dataEnd = nGot if nGot > 100 + 3 * ptr_len: dataEnd = 100 + 3 * ptr_len nGot -= dataEnd val_data = data[3 * ptr_len:dataEnd] dataEnd = dataEnd - 3 * ptr_len vals = unpack_from((dataEnd / 4) * "i", val_data) data = data[100 + 3 * ptr_len:] for i, v in enumerate(vals): a = abs(v) self.result.append(a) if self.learnDialog is None: #normal mode if a > 6500: #button held? if self.CodeValid(self.result): #eg.PrintNotice("Sending ir code %s"%str(self.result)) self.plugin.irDecoder.Decode( self.result, len(self.result)) self.result = [] if not self.learnDialog is None: #learn mode if header[0] == 1: #one "learn" chunk self.timeout = self.learnTimeout except: pass self.SetReceiving(False)