def _get_execute(metric): if not os.access(metric.path, os.X_OK): raise BaseException("File is not executable: '%s'" % metric.path) logger.debug('Executing %s', metric.path) proc = Popen(metric.path, stdout=PIPE, stderr=PIPE, close_fds=True) start_time = time.time() while time.time() - start_time < MtxTableImpl.EXEC_TIMEOUT: if proc.poll() is None: time.sleep(0.1) else: break else: if hasattr(proc, 'kill'): # python >= 2.6 kill_childs(proc.pid) proc.terminate() else: kill_childs(proc.pid) os.kill(proc.pid, signal.SIGTERM) raise BaseException('Timeouted') stdout, stderr = proc.communicate() if proc.returncode > 0: raise BaseException(stderr if stderr else 'exitcode: %d' % proc.returncode) return stdout
def _get_execute(metric): if not os.access(metric.path, os.X_OK): raise BaseException("File is not executable: '%s'" % metric.path) exec_timeout = 3 close_fds = not linux.os.windows_family proc = subprocess.Popen(metric.path, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=close_fds) timeout_time = time.time() + exec_timeout while time.time() < timeout_time: if proc.poll() is None: time.sleep(0.2) else: break else: kill_childs(proc.pid) if hasattr(proc, 'terminate'): # python >= 2.6 proc.terminate() else: os.kill(proc.pid, signal.SIGTERM) raise BaseException('Timeouted') stdout, stderr = proc.communicate() if proc.returncode > 0: raise BaseException(stderr if stderr else 'exitcode: %d' % proc.returncode) return stdout.strip()
def stop(self): """ Stop MMS agent """ if _MMSAgent.ps: util.kill_childs(_MMSAgent.ps.pid) _MMSAgent.ps.terminate() _MMSAgent.ps = None
def do_stop(self): LOG.info('Stopping UpdateClient') if not linux.os.windows: LOG.debug('Kill child processes') util.kill_childs(os.getpid()) time.sleep(.05) # Interrupt main thread if self.api_thread: LOG.debug('Stopping API') self.api.shutdown() self.api_server.shutdown() self.api_thread.join() if os.path.exists(self.pid_file): os.unlink(self.pid_file) LOG.info('Stopped')