示例#1
0
 def _stop(self):
     LOG.debug(self._stopping_msg)
     try:
         if not os.path.exists(self.config['pid_file']):
             msg = "Can't stop, pid file %s doesn't exist\n" % self.config[
                 'pid_file']
             sys.stderr.write(helper.colorize(helper.Color.FAIL, msg))
             return
         with file(self.config['pid_file'], 'r') as pf:
             pid = int(pf.read().strip())
         for ps in psutil.process_iter():
             if ps.name() == self.name[0:15]:
                 # TODO
                 # SIGINT
                 helper.kill_children(pid)
                 helper.kill(pid)
                 break
         else:
             msg = "Process with name {0} doesn't exists".format(self.name)
             raise Exception(msg)
         LOG.info('Stopped')
         helper.delete_file(self.config['pid_file'])
     except:
         msg = "Can't stop, reason: {error}".format(error=helper.exc_info())
         raise Exception(msg)
示例#2
0
    def run(self):
        while True:
            start_time = time.time()
            LOG.info('Start iteration')

            p = mp.Process(target=self.__call__, args=())
            p.start()
            p.join(300)
            if p.is_alive():
                LOG.error('Timeout. Terminating ...')
                try:
                    helper.kill_child(p.pid)
                    helper.kill(p.pid)
                except:
                    LOG.exception('Exception')
                p.terminate()

            LOG.info('Working time: %s' % (time.time() - start_time))

            if not CONFIG['interval']:
                break

            sleep_time = start_time + CONFIG['interval'] - time.time()
            if sleep_time > 0:
                time.sleep(sleep_time)
示例#3
0
文件: cron.py 项目: alisheikh/scalr
 def stop(self):
     LOG.debug('Stopping...')
     try:
         with file(self.pid_file, 'r') as pf:
             pid = int(pf.read().strip())
     except IOError:
         msg = "Can't open pid file %s. Stop failed" % self.pid_file
         LOG.error(msg)
         return
     try:
         helper.kill_child(pid)
         helper.kill(pid)
     except:
         LOG.error(helper.exc_info())
     LOG.info('Stopped')
示例#4
0
    def stop(self):
        LOG.info('Stop')
        if not self.pid_file:
            raise Exception("You must specify pid file")

        try:
            pf = file(self.pid_file, 'r')
            pid = int(pf.read().strip())
            pf.close()
        except IOError:
            LOG.error("Pid file %s dosn't exist" % self.pid_file)
            return
        except ValueError:
            LOG.error("Wrong value in pid file %s" % self.pid_file)
            self._delete_pid_file()
            return

        try:
            if helper.check_pid(self.pid_file):
                helper.kill_child(pid)
                helper.kill(pid)
        except:
            LOG.error(helper.exc_info())
示例#5
0
 def _stop(self):
     LOG.debug(self._stopping_msg)
     try:
         if not os.path.exists(self.config['pid_file']):
             msg = "Can't stop, pid file %s doesn't exist\n" % self.config['pid_file']
             sys.stderr.write(helper.colorize(helper.Color.FAIL, msg))
             return
         with file(self.config['pid_file'], 'r') as pf:
             pid = int(pf.read().strip())
         for ps in psutil.process_iter():
             if ps.name() == self.name[0:15]:
                 # TODO
                 # SIGINT
                 helper.kill_children(pid)
                 helper.kill(pid)
                 break
         else:
             msg = "Process with name {0} doesn't exists".format(self.name)
             raise Exception(msg)
         LOG.info('Stopped')
         helper.delete_file(self.config['pid_file'])
     except:
         msg = "Can't stop, reason: {error}".format(error=helper.exc_info())
         raise Exception(msg)