def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) logger.info('service stopping') win32event.SetEvent(self.stop_event)
def _testInterpInThread(self, stopEvent, interp): try: self._doTestInThread(interp) finally: win32event.SetEvent(stopEvent)
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" ) 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 return rc = win32event.WaitForMultipleObjects(handles, False, self.timeout) 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
def stop(self): self._running = False with self._stop_event_lock: if self._stop_event is not None: win32event.SetEvent(self._stop_event) self.wait()
def SvcStop(self): self.logger.info("service is stop....") self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop) self.run = False
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)
def _DocumentStateChanged(self): win32event.SetEvent(self.adminEvent)
def SvcStop(self): # tell the SCM we're shutting down self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) # fire the stop event win32event.SetEvent(self.hWaitStop)
def OnQuit(self): thread = win32api.GetCurrentThreadId() print("OnQuit event processed on thread %d" % thread) win32event.SetEvent(self.event)
def SvcStop(self): self.isAlive = False self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop) sys.exit()
def SvcStop(self): servicemanager.LogInfoMsg("Service is stopping.") lheader("Stopping") self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.haltEvent) self.ReportServiceStatus(win32service.SERVICE_STOPPED)
def SvcStop(self): # logging.info("Stopping....") self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop)
def SvcStop(self): # Set the stop event - the main loop takes care of termination. win32event.SetEvent(self.hWaitStop)
def SvcStop(self): servicemanager.LogInfoMsg('\n\nStopping service') self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop)
def SvcStop(self): # tell Service Manager we are trying to stop (required) self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) # set the event to call win32event.SetEvent(self.hWaitStop) self.isAlive = False
def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.stop_event) self.stop_requested = True
def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.stop_event) self.ReportServiceStatus(win32service.SERVICE_STOPPED) sys.exit()
def SvcStop(self): # Before we do anything, tell the SCM we are starting the stop process. self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) # And set my event. win32event.SetEvent(self.hWaitStop)
def SvcStop(self) -> None: self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) self._isAlive = False win32event.SetEvent(self._hWaitStop)
def threadLoop(): """main function for the working thread""" while True: win32event.WaitForSingleObject(event1, win32event.INFINITE) brain_turn() win32event.SetEvent(event2)
def SignalStop(self): win32event.SetEvent(self.stopEvent)
def turn(): """start thinking""" global terminateAI terminateAI = 0 win32event.ResetEvent(event2) win32event.SetEvent(event1)
def SvcStop(self): # Tell the SCM we are starting the stop process. self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) # Set the stop event - the main loop takes care of termination. win32event.SetEvent(self.hWaitStop)
def SvcStop(self): self.httpd.shutdown() log_exit() time.sleep(3) self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop)
def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop)
def SvcStop(self): self.logger.info("Stopping {} service".format(self._svc_display_name_)) self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop)
def StopMonitoringPower(self): assert self._ippet_handle, ( 'Called StopMonitoringPower() before StartMonitoringPower().') try: # Stop IPPET. with contextlib.closing( win32event.OpenEvent(win32event.EVENT_MODIFY_STATE, False, QUIT_EVENT)) as quit_event: win32event.SetEvent(quit_event) # Wait for IPPET process to exit. wait_code = win32event.WaitForSingleObject(self._ippet_handle, 20000) if wait_code != win32event.WAIT_OBJECT_0: if wait_code == win32event.WAIT_TIMEOUT: raise IppetError('Timed out waiting for IPPET to close.') else: raise IppetError( 'Error code %d while waiting for IPPET to close.' % wait_code) finally: # If we need to, forcefully kill IPPET. try: exit_code = win32process.GetExitCodeProcess(self._ippet_handle) if exit_code == win32con.STILL_ACTIVE: win32process.TerminateProcess(self._ippet_handle, 0) raise IppetError( 'IPPET is still running but should have stopped.') elif exit_code != 0: raise IppetError('IPPET closed with exit code %d.' % exit_code) finally: self._ippet_handle.Close() self._ippet_handle = None # Read IPPET's log file. log_file = os.path.join(self._output_dir, 'ippet_log_processes.xls') try: with open(log_file, 'r') as f: reader = csv.DictReader(f, dialect='excel-tab') data = list(reader)[ 1:] # The first iteration only reports temperature. except IOError: logging.error('Output directory %s contains: %s', self._output_dir, os.listdir(self._output_dir)) raise shutil.rmtree(self._output_dir) self._output_dir = None def get(*args, **kwargs): """Pull all iterations of a field from the IPPET data as a list. Args: args: A list representing the field name. mult: A cosntant to multiply the field's value by, for unit conversions. default: The default value if the field is not found in the iteration. Returns: A list containing the field's value across all iterations. """ key = '\\\\.\\' + '\\'.join(args) def value(line): if key in line: return line[key] elif 'default' in kwargs: return kwargs['default'] else: raise KeyError('Key "%s" not found in data and ' 'no default was given.' % key) return [ float(value(line)) * kwargs.get('mult', 1) for line in data ] result = { 'identifier': 'ippet', 'power_samples_mw': get('Power(_Total)', 'Package W', mult=1000), 'energy_consumption_mwh': sum( map(operator.mul, get('Power(_Total)', 'Package W', mult=1000), get('sys', 'Interval(secs)', mult=1. / 3600.))), 'component_utilization': { 'whole_package': { 'average_temperature_c': statistics.ArithmeticMean( get('Temperature(Package)', 'Current C')), }, 'cpu': { 'power_samples_mw': get('Power(_Total)', 'CPU W', mult=1000), 'energy_consumption_mwh': sum( map(operator.mul, get('Power(_Total)', 'CPU W', mult=1000), get('sys', 'Interval(secs)', mult=1. / 3600.))), }, 'disk': { 'power_samples_mw': get('Power(_Total)', 'Disk W', mult=1000), 'energy_consumption_mwh': sum( map(operator.mul, get('Power(_Total)', 'Disk W', mult=1000), get('sys', 'Interval(secs)', mult=1. / 3600.))), }, 'gpu': { 'power_samples_mw': get('Power(_Total)', 'GPU W', mult=1000), 'energy_consumption_mwh': sum( map(operator.mul, get('Power(_Total)', 'GPU W', mult=1000), get('sys', 'Interval(secs)', mult=1. / 3600.))), }, }, } # Find Chrome processes in data. Note that this won't work if there are # extra Chrome processes lying around. chrome_keys = set() for iteration in data: for key in iteration.iterkeys(): parts = key.split('\\') if (len(parts) >= 4 and re.match( r'Process\(Google Chrome [0-9]+\)', parts[3])): chrome_keys.add(parts[3]) # Add Chrome process power usage to result. # Note that this is only an estimate of Chrome's CPU power usage. if chrome_keys: per_process_power_usage = [ get(key, 'CPU Power W', default=0, mult=1000) for key in chrome_keys ] result['application_energy_consumption_mwh'] = (sum( map(operator.mul, map(sum, zip(*per_process_power_usage)), get('sys', 'Interval(secs)', mult=1. / 3600.)))) return result
def __close__(self): if self.SerialThread: win32event.SetEvent(self.stopEvent) self.SerialThread.join(1.0) self.serial.close()
def __stop__(self): eg.PrintNotice("MCE_Vista: Stopping Mce Vista plugin") win32event.SetEvent(self.hFinishedEvent) self.client.Stop() self.client = None
def _StopThread(self): win32event.SetEvent(self.hStopThread) self.hStopThread = None