Esempio n. 1
0
 def __repeatDoMethod(self, task):
     """
     Called when a task execute function returns Task.again because
     it wants the task to execute again after the same or a modified
     delay (set 'delayTime' on the task object to change the delay)
     """
     if (not task._removed):
         # be sure to ask the globalClock for the current frame time
         # rather than use a cached value; globalClock's frame time may
         # have been synced since the start of this frame
         currentTime = self.__getTime()
         # Cache the time we should wake up for easier sorting
         task.wakeTime = currentTime + task.delayTime
         # Push this onto the doLaterList. The heap maintains the sorting.
         heappush(self.__doLaterList, task)
         if self.fVerbose:
             # Alert the world, a new task is born!
             messenger.send('TaskManager-againDoLater',
                            sentArgs = [task, task.name, task.id])
Esempio n. 2
0
    def doMethodLater(self, delayTime, funcOrTask, name, extraArgs=None,
            priority=0, uponDeath=None, appendTask=False):
        if delayTime < 0:
            self.notify.warning('doMethodLater: added task: %s with negative delay: %s' % (name, delayTime))
        if isinstance(funcOrTask, Task):
            task = funcOrTask
        elif callable(funcOrTask):
            task = Task(funcOrTask, priority)
        else:
            self.notify.error('doMethodLater: Tried to add a task that was not a Task or a func')
        task.setPriority(priority)
        task.name = name
        if extraArgs == None:
            extraArgs = []
            appendTask = True

        # if told to, append the task object to the extra args list so the
        # method called will be able to access any properties on the task
        if appendTask:
            extraArgs.append(task)
          
        task.extraArgs = extraArgs
        if uponDeath:
            task.uponDeath = uponDeath

        # TaskManager.notify.debug('spawning doLater: %s' % (task))
        # Add this task to the nameDict
        nameList = self.nameDict.get(name)
        if nameList:
            nameList.append(task)
        else:
            self.nameDict[name] = [task]
        currentTime = self.__getTime()
        # Cache the time we should wake up for easier sorting
        task.delayTime = delayTime
        task.wakeTime = currentTime + delayTime
        # Push this onto the doLaterList. The heap maintains the sorting.
        heappush(self.__doLaterList, task)
        if self.fVerbose:
            # Alert the world, a new task is born!
            messenger.send('TaskManager-spawnDoLater',
                           sentArgs = [task, task.name, task.id])
        return task