def checkout(self, numCores): if numCores < 1: raise ttypes.RndException(1, "Cannot reserve 0 slots") result = [] with self.__lock: open_slots = self.__slots logger.info("Open slots: %s", list(open_slots)) if numCores > len(open_slots): raise ttypes.RndException(1, "No more open slots") result = [open_slots.pop() for _ in xrange(numCores)] logger.info("Checked out CPUS: %s", result) return result
def killRunningTask(self, procId, reason): """ Kill a currently running task by its procId. """ logger.info("kill requested for procId %s, %s", procId, reason) with self.__lock: try: pthread = self.__threads[procId].pthread except KeyError: err = "Process %s not found" % procId logger.warn(err) # TODO: Raise a proper exception type? or # fail quietly? raise ttypes.RndException(1, err) _, not_killed = pthread.killProcess() if not_killed: err = "Failed to kill the following pids for prodId %s: %s" % \ (procId, ','.join(not_killed)) logger.warn(err) raise ttypes.RndException(1, err)