def addSession(self, ID, time_table, priority=1):
"""Add a session into executor.
Args:
ID (str): session ID
time_table::
{
time(float): cmd(SON),
time(float): cmd(SON),
time(float): cmd(SON),
.....
}
priority (int): the priority of execution of this session
Note:
"time" in time_table represent the delay of execution after executor begin.
When duration of certain operation is too long, whole execution will delay.
Read more about scheduler in: https://docs.python.org/2/library/sched.html
"""
if ID in self.sessions_queue:
# raise KeyError('ID [%s] already exist!' % ID)
logger.warning('ID [%s] already exist in executor\'s session queue!' % ID)
logger.warning('New operation will overwrite old one')
time_table = {t*self.time_scale_factor: time_table[t] for t in time_table}
self.exec_time_cache[ID] = []
self.sessions_queue[ID] = time_table
cmd_type = time_table.values()[0].keys()[0]
if cmd_type in self.type_cache:
self.type_cache[cmd_type].append(ID)
for t in time_table:
self.sche.enter(t+3, priority, self.runCommand, [ID, time_table[t]])
评论列表
文章目录