AsyncTaskChain

from panda3d.core import AsyncTaskChain
class AsyncTaskChain

Bases: TypedReferenceCount, Namable

The AsyncTaskChain is a subset of the AsyncTaskManager. Each chain maintains a separate list of tasks, and will execute them with its own set of threads. Each chain may thereby operate independently of the other chains.

The AsyncTaskChain will spawn a specified number of threads (possibly 0) to serve the tasks. If there are no threads, you must call poll() from time to time to serve the tasks in the main thread. Normally this is done by calling AsyncTaskManager::poll().

Each task will run exactly once each epoch. Beyond that, the tasks’ sort and priority values control the order in which they are run: tasks are run in increasing order by sort value, and within the same sort value, they are run roughly in decreasing order by priority value, with some exceptions for parallelism. Tasks with different sort values are never run in parallel together, but tasks with different priority values might be (if there is more than one thread).

Inheritance diagram

Inheritance diagram of AsyncTaskChain

__init__(*args, **kwargs)
add()

C++ Interface: add(const AsyncTaskChain self, AsyncTask task)

/**
  • Adds the indicated task to the active queue. The task must be inactive, and

  • may not have been added to any queue (including the current one).

*/

getActiveTasks()

C++ Interface: get_active_tasks(AsyncTaskChain self)

/**
  • Returns the set of tasks that are active (and not sleeping) on the task

  • chain, at the time of the call.

*/

getClassType()

C++ Interface: get_class_type()

getFrameBudget()

C++ Interface: get_frame_budget(AsyncTaskChain self)

/**
  • Returns the maximum amount of time per frame the tasks on this chain are

  • granted for execution. See set_frame_budget().

*/

getFrameSync()

C++ Interface: get_frame_sync(AsyncTaskChain self)

/**
  • Returns the frame_sync flag. See set_frame_sync().

*/

getNextWakeTime()

C++ Interface: get_next_wake_time(AsyncTaskChain self)

/**
  • Returns the scheduled time (on the manager’s clock) of the next sleeping

  • task, on any task chain, to awaken. Returns -1 if there are no sleeping

  • tasks.

*/

getNumRunningThreads()

C++ Interface: get_num_running_threads(AsyncTaskChain self)

/**
  • Returns the number of threads that have been created and are actively

  • running. This will return 0 before the threads have been started; it will

  • also return 0 if thread support is not available.

*/

getNumTasks()

C++ Interface: get_num_tasks(AsyncTaskChain self)

/**
  • Returns the number of tasks that are currently active or sleeping within

  • the task chain.

*/

getNumThreads()

C++ Interface: get_num_threads(AsyncTaskChain self)

/**
  • Returns the number of threads that will be servicing tasks for this chain.

  • Also see get_num_running_threads().

*/

getSleepingTasks()

C++ Interface: get_sleeping_tasks(AsyncTaskChain self)

/**
  • Returns the set of tasks that are sleeping (and not active) on the task

  • chain, at the time of the call.

*/

getTasks()

C++ Interface: get_tasks(AsyncTaskChain self)

/**
  • Returns the set of tasks that are active or sleeping on the task chain, at

  • the time of the call.

*/

getThreadPriority()

C++ Interface: get_thread_priority(AsyncTaskChain self)

/**
  • Returns the priority associated with threads that serve this task chain.

*/

getTickClock()

C++ Interface: get_tick_clock(AsyncTaskChain self)

/**
  • Returns the tick_clock flag. See set_tick_clock().

*/

getTimeslicePriority()

C++ Interface: get_timeslice_priority(AsyncTaskChain self)

/**
  • Returns the timeslice_priority flag. This changes the interpretation of

  • priority, and the number of times per epoch each task will run. See

  • set_timeslice_priority().

*/

get_active_tasks()

C++ Interface: get_active_tasks(AsyncTaskChain self)

/**
  • Returns the set of tasks that are active (and not sleeping) on the task

  • chain, at the time of the call.

*/

get_class_type()

C++ Interface: get_class_type()

get_frame_budget()

C++ Interface: get_frame_budget(AsyncTaskChain self)

/**
  • Returns the maximum amount of time per frame the tasks on this chain are

  • granted for execution. See set_frame_budget().

*/

get_frame_sync()

C++ Interface: get_frame_sync(AsyncTaskChain self)

/**
  • Returns the frame_sync flag. See set_frame_sync().

*/

get_next_wake_time()

C++ Interface: get_next_wake_time(AsyncTaskChain self)

/**
  • Returns the scheduled time (on the manager’s clock) of the next sleeping

  • task, on any task chain, to awaken. Returns -1 if there are no sleeping

  • tasks.

*/

get_num_running_threads()

C++ Interface: get_num_running_threads(AsyncTaskChain self)

/**
  • Returns the number of threads that have been created and are actively

  • running. This will return 0 before the threads have been started; it will

  • also return 0 if thread support is not available.

*/

get_num_tasks()

C++ Interface: get_num_tasks(AsyncTaskChain self)

/**
  • Returns the number of tasks that are currently active or sleeping within

  • the task chain.

*/

get_num_threads()

C++ Interface: get_num_threads(AsyncTaskChain self)

/**
  • Returns the number of threads that will be servicing tasks for this chain.

  • Also see get_num_running_threads().

*/

get_sleeping_tasks()

C++ Interface: get_sleeping_tasks(AsyncTaskChain self)

/**
  • Returns the set of tasks that are sleeping (and not active) on the task

  • chain, at the time of the call.

*/

get_tasks()

C++ Interface: get_tasks(AsyncTaskChain self)

/**
  • Returns the set of tasks that are active or sleeping on the task chain, at

  • the time of the call.

*/

get_thread_priority()

C++ Interface: get_thread_priority(AsyncTaskChain self)

/**
  • Returns the priority associated with threads that serve this task chain.

*/

get_tick_clock()

C++ Interface: get_tick_clock(AsyncTaskChain self)

/**
  • Returns the tick_clock flag. See set_tick_clock().

*/

get_timeslice_priority()

C++ Interface: get_timeslice_priority(AsyncTaskChain self)

/**
  • Returns the timeslice_priority flag. This changes the interpretation of

  • priority, and the number of times per epoch each task will run. See

  • set_timeslice_priority().

*/

hasTask()

C++ Interface: has_task(AsyncTaskChain self, AsyncTask task)

/**
  • Returns true if the indicated task has been added to this AsyncTaskChain,

  • false otherwise.

*/

has_task()

C++ Interface: has_task(AsyncTaskChain self, AsyncTask task)

/**
  • Returns true if the indicated task has been added to this AsyncTaskChain,

  • false otherwise.

*/

isStarted()

C++ Interface: is_started(AsyncTaskChain self)

/**
  • Returns true if the thread(s) have been started and are ready to service

  • requests, false otherwise. If this is false, the next call to add() or

  • add_and_do() will automatically start the threads.

*/

is_started()

C++ Interface: is_started(AsyncTaskChain self)

/**
  • Returns true if the thread(s) have been started and are ready to service

  • requests, false otherwise. If this is false, the next call to add() or

  • add_and_do() will automatically start the threads.

*/

output()

C++ Interface: output(AsyncTaskChain self, ostream out)

/**

*/

poll()

C++ Interface: poll(const AsyncTaskChain self)

/**
  • Runs through all the tasks in the task list, once, if the task chain is

  • running in single-threaded mode (no threads available). This method does

  • nothing in threaded mode, so it may safely be called in either case.

  • Normally, you would not call this function directly; instead, call

  • AsyncTaskManager::poll(), which polls all of the task chains in sequence.

*/

setFrameBudget()

C++ Interface: set_frame_budget(const AsyncTaskChain self, double frame_budget)

/**
  • Sets the maximum amount of time per frame the tasks on this chain are

  • granted for execution. If this is less than zero, there is no limit; if it

  • is >= 0, it represents a maximum amount of time (in seconds) that will be

  • used to execute tasks. If this time is exceeded in any one frame, the task

  • chain will stop executing tasks until the next frame, as defined by the

  • TaskManager’s clock.

*/

setFrameSync()

C++ Interface: set_frame_sync(const AsyncTaskChain self, bool frame_sync)

/**
  • Sets the frame_sync flag. When this flag is true, this task chain will be

  • forced to sync with the TaskManager’s clock. It will run no faster than

  • one epoch per clock frame.

  • 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 task chains. Non-threaded task chains

  • are automatically synchronous.

*/

setNumThreads()

C++ Interface: set_num_threads(const AsyncTaskChain self, int num_threads)

/**
  • Changes the number of threads for this task chain. This may require

  • stopping the threads if they are already running.

*/

setThreadPriority()

C++ Interface: set_thread_priority(const AsyncTaskChain self, int priority)

/**
  • Changes the priority associated with threads that serve this task chain.

  • This may require stopping the threads if they are already running.

*/

setTickClock()

C++ Interface: set_tick_clock(const AsyncTaskChain self, bool tick_clock)

/**
  • Sets the tick_clock flag. When this is true, get_clock()->tick() will be

  • called automatically at each task epoch. This is false by default.

*/

setTimeslicePriority()

C++ Interface: set_timeslice_priority(const AsyncTaskChain self, bool timeslice_priority)

/**
  • Sets the timeslice_priority flag. This changes the interpretation of

  • priority, and the number of times per epoch each task will run.

  • When this flag is true, some tasks might not run in any given epoch.

  • Instead, tasks with priority higher than 1 will be given precedence, in

  • proportion to the amount of time they have already used. This gives

  • higher-priority tasks more runtime than lower-priority tasks. Each task

  • gets the amount of time proportional to its priority value, so a task with

  • priority 100 will get five times as much processing time as a task with

  • priority 20. For these purposes, priority values less than 1 are deemed to

  • be equal to 1.

  • When this flag is false (the default), all tasks are run exactly once each

  • epoch, round-robin style. Priority is only used to determine which task

  • runs first within tasks of the same sort value.

*/

set_frame_budget()

C++ Interface: set_frame_budget(const AsyncTaskChain self, double frame_budget)

/**
  • Sets the maximum amount of time per frame the tasks on this chain are

  • granted for execution. If this is less than zero, there is no limit; if it

  • is >= 0, it represents a maximum amount of time (in seconds) that will be

  • used to execute tasks. If this time is exceeded in any one frame, the task

  • chain will stop executing tasks until the next frame, as defined by the

  • TaskManager’s clock.

*/

set_frame_sync()

C++ Interface: set_frame_sync(const AsyncTaskChain self, bool frame_sync)

/**
  • Sets the frame_sync flag. When this flag is true, this task chain will be

  • forced to sync with the TaskManager’s clock. It will run no faster than

  • one epoch per clock frame.

  • 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 task chains. Non-threaded task chains

  • are automatically synchronous.

*/

set_num_threads()

C++ Interface: set_num_threads(const AsyncTaskChain self, int num_threads)

/**
  • Changes the number of threads for this task chain. This may require

  • stopping the threads if they are already running.

*/

set_thread_priority()

C++ Interface: set_thread_priority(const AsyncTaskChain self, int priority)

/**
  • Changes the priority associated with threads that serve this task chain.

  • This may require stopping the threads if they are already running.

*/

set_tick_clock()

C++ Interface: set_tick_clock(const AsyncTaskChain self, bool tick_clock)

/**
  • Sets the tick_clock flag. When this is true, get_clock()->tick() will be

  • called automatically at each task epoch. This is false by default.

*/

set_timeslice_priority()

C++ Interface: set_timeslice_priority(const AsyncTaskChain self, bool timeslice_priority)

/**
  • Sets the timeslice_priority flag. This changes the interpretation of

  • priority, and the number of times per epoch each task will run.

  • When this flag is true, some tasks might not run in any given epoch.

  • Instead, tasks with priority higher than 1 will be given precedence, in

  • proportion to the amount of time they have already used. This gives

  • higher-priority tasks more runtime than lower-priority tasks. Each task

  • gets the amount of time proportional to its priority value, so a task with

  • priority 100 will get five times as much processing time as a task with

  • priority 20. For these purposes, priority values less than 1 are deemed to

  • be equal to 1.

  • When this flag is false (the default), all tasks are run exactly once each

  • epoch, round-robin style. Priority is only used to determine which task

  • runs first within tasks of the same sort value.

*/

startThreads()

C++ Interface: start_threads(const AsyncTaskChain self)

/**
  • Starts any requested threads to service the tasks on the queue. This is

  • normally not necessary, since adding a task will start the threads

  • automatically.

*/

start_threads()

C++ Interface: start_threads(const AsyncTaskChain self)

/**
  • Starts any requested threads to service the tasks on the queue. This is

  • normally not necessary, since adding a task will start the threads

  • automatically.

*/

stopThreads()

C++ Interface: stop_threads(const AsyncTaskChain self)

/**
  • Stops any threads that are currently running. If any tasks are still

  • pending and have not yet been picked up by a thread, they will not be

  • serviced unless poll() or start_threads() is later called.

*/

stop_threads()

C++ Interface: stop_threads(const AsyncTaskChain self)

/**
  • Stops any threads that are currently running. If any tasks are still

  • pending and have not yet been picked up by a thread, they will not be

  • serviced unless poll() or start_threads() is later called.

*/

upcastToNamable()

C++ Interface: upcast_to_Namable(const AsyncTaskChain self)

upcast from AsyncTaskChain to Namable

upcastToTypedReferenceCount()

C++ Interface: upcast_to_TypedReferenceCount(const AsyncTaskChain self)

upcast from AsyncTaskChain to TypedReferenceCount

upcast_to_Namable()

C++ Interface: upcast_to_Namable(const AsyncTaskChain self)

upcast from AsyncTaskChain to Namable

upcast_to_TypedReferenceCount()

C++ Interface: upcast_to_TypedReferenceCount(const AsyncTaskChain self)

upcast from AsyncTaskChain to TypedReferenceCount

waitForTasks()

C++ Interface: wait_for_tasks(const AsyncTaskChain self)

/**
  • Blocks until the task list is empty.

*/

wait_for_tasks()

C++ Interface: wait_for_tasks(const AsyncTaskChain self)

/**
  • Blocks until the task list is empty.

*/

write()

C++ Interface: write(AsyncTaskChain self, ostream out, int indent_level)

/**

*/