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()
评论列表
文章目录