sharedmemory.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:temboard-agent 作者: dalibo 项目源码 文件源码
def purge_expired(self, ttl, logger):
        """
        In charge of removing old Commands (when Command's last update time +
        given TTL is prior to current timestamp and the worker finished its
        work on it) from the shared array.
        """
        for i in range(0, self.size):
            if len(self.commands[i].commandid) == T_COMMANDID_SIZE and \
                (self.commands[i].time + ttl) < time.time() and \
                (self.commands[i].state == COMMAND_DONE or
                    self.commands[i].state == COMMAND_ERROR):
                logger.debug("Removing command with commandid=%s" %
                             (self.commands[i].commandid))
                # Deletion: overwrite array element by a null Command.
                self.commands[i] = Command()
            # We need to ckeck if the processes executing commands with a
            # state = COMMAND_START are stil alive and then remove the
            # command if they are not.
            if len(self.commands[i].commandid) == T_COMMANDID_SIZE and \
               self.commands[i].state == COMMAND_START and \
               self.commands[i].pid > 0:
                try:
                    os.getpgid(self.commands[i].pid)
                except OSError:
                    logger.debug("Removing command with commandid=%s." % (
                                 self.commands[i].commandid))
                    self.commands[i] = Command()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号