Browse Source

regularize extraArgs

David Rose 18 years ago
parent
commit
afabf9df4e
1 changed files with 24 additions and 17 deletions
  1. 24 17
      direct/src/task/Task.py

+ 24 - 17
direct/src/task/Task.py

@@ -19,9 +19,9 @@ import fnmatch
 import string
 import string
 import signal
 import signal
 try:
 try:
-  from libp3heapq import heappush, heappop, heapify
+    from libp3heapq import heappush, heappop, heapify
 except:
 except:
-  from libheapq import heappush, heappop, heapify
+    from libheapq import heappush, heappop, heapify
 import types
 import types
 
 
 if __debug__:
 if __debug__:
@@ -91,7 +91,7 @@ class Task:
             self.maxDt = 0.0
             self.maxDt = 0.0
             self.runningTotal = 0.0
             self.runningTotal = 0.0
             self.pstats = None
             self.pstats = None
-        self.extraArgs = None
+        self.extraArgs = []
         # Used for doLaters
         # Used for doLaters
         self.wakeTime = 0.0
         self.wakeTime = 0.0
         # for repeating doLaters
         # for repeating doLaters
@@ -456,14 +456,18 @@ class TaskManager:
             self.notify.error('doMethodLater: Tried to add a task that was not a Task or a func')
             self.notify.error('doMethodLater: Tried to add a task that was not a Task or a func')
         task.setPriority(priority)
         task.setPriority(priority)
         task.name = name
         task.name = name
-        task.extraArgs = extraArgs
-        if uponDeath:
-            task.uponDeath = uponDeath
+        if extraArgs == None:
+            extraArgs = []
+            appendTask = True
 
 
         # if told to, append the task object to the extra args list so the
         # 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
         # method called will be able to access any properties on the task
-        if (appendTask == True and extraArgs != None):
+        if appendTask:
             extraArgs.append(task)
             extraArgs.append(task)
+          
+        task.extraArgs = extraArgs
+        if uponDeath:
+            task.uponDeath = uponDeath
 
 
         # TaskManager.notify.debug('spawning doLater: %s' % (task))
         # TaskManager.notify.debug('spawning doLater: %s' % (task))
         # Add this task to the nameDict
         # Add this task to the nameDict
@@ -484,7 +488,8 @@ class TaskManager:
                            sentArgs = [task, task.name, task.id])
                            sentArgs = [task, task.name, task.id])
         return task
         return task
 
 
-    def add(self, funcOrTask, name, priority=0, extraArgs=None, uponDeath=None):
+    def add(self, funcOrTask, name, priority=0, extraArgs=None, uponDeath=None,
+            appendTask = False):
         """
         """
         Add a new task to the taskMgr.
         Add a new task to the taskMgr.
         You can add a Task object or a method that takes one argument.
         You can add a Task object or a method that takes one argument.
@@ -499,6 +504,15 @@ class TaskManager:
                 'add: Tried to add a task that was not a Task or a func')
                 'add: Tried to add a task that was not a Task or a func')
         task.setPriority(priority)
         task.setPriority(priority)
         task.name = name
         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
         task.extraArgs = extraArgs
         if uponDeath:
         if uponDeath:
             task.uponDeath = uponDeath
             task.uponDeath = uponDeath
@@ -644,11 +658,7 @@ class TaskManager:
             startTime = self.trueClock.getShortTime()
             startTime = self.trueClock.getShortTime()
             
             
             # don't record timing info
             # don't record timing info
-            if task.extraArgs != None:
-                ret = task(*task.extraArgs)
-            else:
-                ret = task(task)
-
+            ret = task(*task.extraArgs)
             endTime = self.trueClock.getShortTime()
             endTime = self.trueClock.getShortTime()
             
             
             # Record the dt
             # Record the dt
@@ -660,10 +670,7 @@ class TaskManager:
             if task.pstats:
             if task.pstats:
                 task.pstats.start()
                 task.pstats.start()
             startTime = self.trueClock.getShortTime()
             startTime = self.trueClock.getShortTime()
-            if task.extraArgs != None:
-                ret = task(*task.extraArgs)
-            else:
-                ret = task(task)
+            ret = task(*task.extraArgs)
             endTime = self.trueClock.getShortTime()
             endTime = self.trueClock.getShortTime()
             if task.pstats:
             if task.pstats:
                 task.pstats.stop()
                 task.pstats.stop()