Panda3D

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Properties | List of all members
TaskManager Class Reference

## Public Member Functions
| __init__ (self)
| __repr__ (self)
| add (self, funcOrTask, name=None, sort=None, extraArgs=None, priority=None, uponDeath=None, appendTask=False, taskChain=None, owner=None, delay=None)
| destroy (self)
| doMethodLater (self, delayTime, funcOrTask, name, extraArgs=None, sort=None, priority=None, taskChain=None, uponDeath=None, appendTask=False, owner=None)
| doYield (self, frameStartTime, nextScheduledTaskTime)
| finalInit (self)
| flushTaskProfiles (self, name=None)
| getAllTasks (self)
| getCurrentTask (self)
| getDoLaters (self)
| getProfileFrames (self)
| getProfileFramesSV (self)
| getProfileSession (self, name=None)
| getProfileTasks (self)
| getProfileTasksSV (self)
| getTasks (self)
| getTasksMatching (self, taskPattern)
| getTasksNamed (self, taskName)
| hasTaskChain (self, chainName)
| hasTaskNamed (self, taskName)
| invokeDefaultHandler (self, signalNumber, stackFrame)
| keyboardInterruptHandler (self, signalNumber, stackFrame)
| logTaskProfiles (self, name=None)
| popupControls (self)
| profileFrames (self, num=None, session=None, callback=None)
| remove (self, taskOrName)
| removeTasksMatching (self, taskPattern)
| replaceMethod (self, oldMethod, newFunction)
| run (self)
| setClock (self, clockObject)
| setProfileFrames (self, profileFrames)
| setProfileTasks (self, profileTasks)
| setupTaskChain (self, chainName, numThreads=None, tickClock=None, threadPriority=None, frameBudget=None, frameSync=None, timeslicePriority=None)
| step (self)
| stop (self)

## Public Attributes
| addedTaskName = task.name
| clearedTaskName = task.name
bool | destroyed = False
bool | fKeyboardInterrupt = False
| globalClock = self.mgr.getClock()
int | interruptCount = 0
| invokeDefaultHandler = 2:
| mgr = AsyncTaskManager.getGlobalPtr()
| resumeFunc = None
bool | running = False
bool | stepping = False

## Static Public Attributes
| do_method_later = doMethodLater
| extendedExceptions = ConfigVariableBool('extended-exceptions', False)
float | MaxEpochSpeed = 1.0/30.0
| notify = directNotify.newCategory("TaskManager")
| pStatsTasks = ConfigVariableBool('pstats-tasks', False)
| taskTimerVerbose = ConfigVariableBool('task-timer-verbose', False)

## Protected Member Functions
| _checkMemLeaks (self)
| _doProfiledFrames (self, numFrames)
| _getLastTaskProfileSession (self)
| _getRandomTask (self)
| _hasProfiledDesignatedTask (self)
| _profileTask (self, profileInfo, task)
| _runTests (self)
| _setProfileTask (self, task)
| _startTrackingMemLeaks (self)
| _stopTrackingMemLeaks (self)
| _unpackIOError (self, ioError)

## Protected Attributes
list | _frameProfileQueue = []
| _frameProfiler = None
| _profileFrames = None
| _profileTask
| _profileTasks = None
| _taskProfileInfo
| _taskProfiler = None

## Properties
| clock = property(lambda self: self.mgr.getClock(), setClock)

## Constructor & Destructor Documentation

## ◆ __init__()

__init__ | ( |  | self | ) |

## Member Function Documentation

## ◆ __repr__()

__repr__ | ( |  | self | ) |

## ◆ _checkMemLeaks()

_checkMemLeaks | ( |  | self | ) |
| protected

## ◆ _doProfiledFrames()

_doProfiledFrames | ( |  | self,
|  |  | numFrames )
| protected

## ◆ _getLastTaskProfileSession()

_getLastTaskProfileSession | ( |  | self | ) |
| protected

## ◆ _getRandomTask()

_getRandomTask | ( |  | self | ) |
| protected

## ◆ _hasProfiledDesignatedTask()

_hasProfiledDesignatedTask | ( |  | self | ) |
| protected

## ◆ _profileTask()

_profileTask | ( |  | self,
|  |  | profileInfo,
|  |  | task )
| protected

## ◆ _runTests()

_runTests | ( |  | self | ) |
| protected

## ◆ _setProfileTask()

_setProfileTask | ( |  | self,
|  |  | task )
| protected

## ◆ _startTrackingMemLeaks()

_startTrackingMemLeaks | ( |  | self | ) |
| protected

## ◆ _stopTrackingMemLeaks()

_stopTrackingMemLeaks | ( |  | self | ) |
| protected

## ◆ _unpackIOError()

_unpackIOError | ( |  | self,
|  |  | ioError )
| protected

## ◆ add()

add | ( |  | self,
|  |  | funcOrTask,
|  |  | name = None,
|  |  | sort = None,
|  |  | extraArgs = None,
|  |  | priority = None,
|  |  | uponDeath = None,
|  |  | appendTask = False,
|  |  | taskChain = None,
|  |  | owner = None,
|  |  | delay = None )

    Add a new task to the taskMgr.  The task will begin executing
    immediately, or next frame if its sort value has already
    passed this frame.

    Parameters:
        funcOrTask: either an existing Task object (not already
            added to the task manager), or a callable function
            object. If this is a function, a new Task object will be
            created and returned. You may also pass in a coroutine
            object.

        name (str): the name to assign to the Task.  Required,
            unless you are passing in a Task object that already has
            a name.

        extraArgs (list): the list of arguments to pass to the task
            function.  If this is omitted, the list is just the task
            object itself.

        appendTask (bool): If this is true, then the task object
            itself will be appended to the end of the extraArgs list
            before calling the function.

        sort (int): the sort value to assign the task.  The default
            sort is 0.  Within a particular task chain, it is
            guaranteed that the tasks with a lower sort value will
            all run before tasks with a higher sort value run.

        priority (int): the priority at which to run the task.  The
            default priority is 0.  Higher priority tasks are run
            sooner, and/or more often.  For historical purposes, if
            you specify a priority without also specifying a sort,
            the priority value is understood to actually be a sort
            value. (Previously, there was no priority value, only a
            sort value, and it was called "priority".)

        uponDeath (bool): a function to call when the task
            terminates, either because it has run to completion, or
            because it has been explicitly removed.

        taskChain (str): the name of the task chain to assign the
            task to.

        owner: an optional Python object that is declared as the
            "owner" of this task for maintenance purposes.  The
            owner must have two methods:
            ``owner._addTask(self, task)``, which is called when the
            task begins, and ``owner._clearTask(self, task)``, which
            is called when the task terminates.  This is all the
            ownermeans.

        delay: an optional amount of seconds to wait before starting
            the task (equivalent to doMethodLater).

    Returns:
        The new Task object that has been added, or the original
        Task object that was passed in.

## ◆ destroy()

destroy | ( |  | self | ) |

## ◆ doMethodLater()

doMethodLater | ( |  | self,
|  |  | delayTime,
|  |  | funcOrTask,
|  |  | name,
|  |  | extraArgs = None,
|  |  | sort = None,
|  |  | priority = None,
|  |  | taskChain = None,
|  |  | uponDeath = None,
|  |  | appendTask = False,
|  |  | owner = None )

    Adds a task to be performed at some time in the future.
    This is identical to `add()`, except that the specified
    delayTime is applied to the Task object first, which means
    that the task will not begin executing until at least the
    indicated delayTime (in seconds) has elapsed.

    After delayTime has elapsed, the task will become active, and
    will run in the soonest possible frame thereafter.  If you
    wish to specify a task that will run in the next frame, use a
    delayTime of 0.

## ◆ doYield()

doYield | ( |  | self,
|  |  | frameStartTime,
|  |  | nextScheduledTaskTime )

## ◆ finalInit()

finalInit | ( |  | self | ) |

## ◆ flushTaskProfiles()

flushTaskProfiles | ( |  | self,
|  |  | name = None )

## ◆ getAllTasks()

getAllTasks | ( |  | self | ) |

    Returns list of all tasks, active and sleeping, in
    arbitrary order.

## ◆ getCurrentTask()

getCurrentTask | ( |  | self | ) |

     Returns the task currently executing on this thread, or
    None if this is being called outside of the task manager.

## ◆ getDoLaters()

getDoLaters | ( |  | self | ) |

    Returns list of all sleeping tasks in arbitrary order.

## ◆ getProfileFrames()

getProfileFrames | ( |  | self | ) |

## ◆ getProfileFramesSV()

getProfileFramesSV | ( |  | self | ) |

## ◆ getProfileSession()

getProfileSession | ( |  | self,
|  |  | name = None )

## ◆ getProfileTasks()

getProfileTasks | ( |  | self | ) |

## ◆ getProfileTasksSV()

getProfileTasksSV | ( |  | self | ) |

## ◆ getTasks()

getTasks | ( |  | self | ) |

    Returns list of all active tasks in arbitrary order.

## ◆ getTasksMatching()

getTasksMatching | ( |  | self,
|  |  | taskPattern )

    Returns a list of all tasks, active or sleeping, with a
    name that matches the pattern, which can include standard
    shell globbing characters like \\*, ?, and [].

## ◆ getTasksNamed()

getTasksNamed | ( |  | self,
|  |  | taskName )

    Returns a list of all tasks, active or sleeping, with the
    indicated name.

## ◆ hasTaskChain()

hasTaskChain | ( |  | self,
|  |  | chainName )

     Returns true if a task chain with the indicated name has
    already been defined, or false otherwise.  Note that
    setupTaskChain() will implicitly define a task chain if it has
    not already been defined, or modify an existing one if it has,
    so in most cases there is no need to check this method
    first.

## ◆ hasTaskNamed()

hasTaskNamed | ( |  | self,
|  |  | taskName )

    Returns true if there is at least one task, active or
    sleeping, with the indicated name.

## ◆ invokeDefaultHandler()

invokeDefaultHandler | ( |  | self,
|  |  | signalNumber,
|  |  | stackFrame )

## ◆ keyboardInterruptHandler()

keyboardInterruptHandler | ( |  | self,
|  |  | signalNumber,
|  |  | stackFrame )

## ◆ logTaskProfiles()

logTaskProfiles | ( |  | self,
|  |  | name = None )

## ◆ popupControls()

popupControls | ( |  | self | ) |

## ◆ profileFrames()

profileFrames | ( |  | self,
|  |  | num = None,
|  |  | session = None,
|  |  | callback = None )

## ◆ remove()

remove | ( |  | self,
|  |  | taskOrName )

    Removes a task from the task manager.  The task is stopped,
    almost as if it had returned task.done.  (But if the task is
    currently executing, it will finish out its current frame
    before being removed.)  You may specify either an explicit
    Task object, or the name of a task.  If you specify a name,
    all tasks with the indicated name are removed.  Returns the
    number of tasks removed.

## ◆ removeTasksMatching()

removeTasksMatching | ( |  | self,
|  |  | taskPattern )

    Removes all tasks whose names match the pattern, which can
    include standard shell globbing characters like \\*, ?, and [].
    See also :meth:`remove()`.

    Returns the number of tasks removed.

## ◆ replaceMethod()

replaceMethod | ( |  | self,
|  |  | oldMethod,
|  |  | newFunction )

## ◆ run()

run | ( |  | self | ) |

    Starts the task manager running.  Does not return until an
    exception is encountered (including KeyboardInterrupt).

## ◆ setClock()

setClock | ( |  | self,
|  |  | clockObject )

## ◆ setProfileFrames()

setProfileFrames | ( |  | self,
|  |  | profileFrames )

## ◆ setProfileTasks()

setProfileTasks | ( |  | self,
|  |  | profileTasks )

## ◆ setupTaskChain()

setupTaskChain | ( |  | self,
|  |  | chainName,
|  |  | numThreads = None,
|  |  | tickClock = None,
|  |  | threadPriority = None,
|  |  | frameBudget = None,
|  |  | frameSync = None,
|  |  | timeslicePriority = None )

    Defines a new task chain.  Each task chain executes tasks
    potentially in parallel with all of the other task chains (if
    numThreads is more than zero).  When a new task is created, it
    may be associated with any of the task chains, by name (or you
    can move a task to another task chain with
    task.setTaskChain()).  You can have any number of task chains,
    but each must have a unique name.

    numThreads is the number of threads to allocate for this task
    chain.  If it is 1 or more, then the tasks on this task chain
    will execute in parallel with the tasks on other task chains.
    If it is greater than 1, then the tasks on this task chain may
    execute in parallel with themselves (within tasks of the same
    sort value).

    If tickClock is True, then this task chain will be responsible
    for ticking the global clock each frame (and thereby
    incrementing the frame counter).  There should be just one
    task chain responsible for ticking the clock, and usually it
    is the default, unnamed task chain.

    threadPriority specifies the priority level to assign to
    threads on this task chain.  It may be one of TPLow, TPNormal,
    TPHigh, or TPUrgent.  This is passed to the underlying
    threading system to control the way the threads are scheduled.

    frameBudget is the maximum amount of time (in seconds) to
    allow this task chain to run per frame.  Set it to -1 to mean
    no limit (the default).  It's not directly related to
    threadPriority.

    frameSync is true to force the task chain to sync to the
    clock.  When this flag is false, the default, the task chain
    will finish all of its tasks and then immediately start from
    the first task again, regardless of the clock frame.  When it
    is true, the task chain will finish all of its tasks and then
    wait for the clock to tick to the next frame before resuming
    the first task.  This only makes sense for threaded tasks
    chains; non-threaded task chains are automatically
    synchronous.

    timeslicePriority is False in the default mode, in which each
    task runs exactly once each frame, round-robin style,
    regardless of the task's priority value; or True to change the
    meaning of priority so that certain tasks are run less often,
    in proportion to their time used and to their priority value.
    See AsyncTaskManager.setTimeslicePriority() for more.

## ◆ step()

step | ( |  | self | ) |

    Invokes the task manager for one frame, and then returns.
    Normally, this executes each task exactly once, though task
    chains that are in sub-threads or that have frame budgets
    might execute their tasks differently.

## ◆ stop()

stop | ( |  | self | ) |

## Member Data Documentation

## ◆ _frameProfileQueue

_frameProfileQueue = []
| protected

## ◆ _frameProfiler

_frameProfiler = None
| protected

## ◆ _profileFrames

_profileFrames = None
| protected

## ◆ _profileTask

_profileTask
| protected

Initial value:
= ScratchPad(
taskFunc = task.getFunction(),
taskArgs = task.getArgs(),
task = task,
profiled = False,
session = None,
)

## ◆ _profileTasks

_profileTasks = None
| protected

## ◆ _taskProfileInfo

_taskProfileInfo
| protected

Initial value:
= ScratchPad(
taskId = None,
profiled = False,
session = None,
)

## ◆ _taskProfiler

_taskProfiler = None
| protected

## ◆ addedTaskName

addedTaskName = task.name

## ◆ clearedTaskName

clearedTaskName = task.name

## ◆ destroyed

bool destroyed = False

## ◆ do_method_later

do_method_later = doMethodLater
| static

## ◆ extendedExceptions

extendedExceptions = ConfigVariableBool('extended-exceptions', False)
| static

## ◆ fKeyboardInterrupt

bool fKeyboardInterrupt = False

## ◆ globalClock

globalClock = self.mgr.getClock()

## ◆ interruptCount

int interruptCount = 0

## ◆ invokeDefaultHandler

invokeDefaultHandler = 2:

## ◆ MaxEpochSpeed

float MaxEpochSpeed = 1.0/30.0
| static

## ◆ mgr

mgr = AsyncTaskManager.getGlobalPtr()

## ◆ notify

notify = directNotify.newCategory("TaskManager")
| static

## ◆ pStatsTasks

pStatsTasks = ConfigVariableBool('pstats-tasks', False)
| static

## ◆ resumeFunc

resumeFunc = None

## ◆ running

bool running = False

## ◆ stepping

bool stepping = False

## ◆ taskTimerVerbose

taskTimerVerbose = ConfigVariableBool('task-timer-verbose', False)
| static

## Property Documentation

## ◆ clock

clock = property(lambda self: self.mgr.getClock(), setClock)
| static