def __init__(self, host, taskpool_host): self.host = host self.workers = SeqTableFactory.createTable(True, self.host + '_workers') self.taskpool_host = taskpool_host self.heartbeat_period = 5 # second self.tasks_cooldown_period = 10 self.last_heartbeat_time = time() # maintain current_tasks to make sure each task can only be ended (success/failure) once # because we have two ways to determine a failure: detected by master and worker it self # following structures should be consistent, so always bind them with a lock self.current_tasks = MongoTable( self.host + '_current_tasks').getTable() #### Queue self.avail_workers = set() self.sem_avail_workers = Semaphore(0) self.worker_lock = RLock() # number of available (up but not working) workers self.logger = Logger.create(self.host)