panda3d.core.AsyncTask

class AsyncTask

Bases: AsyncFuture, Namable

This class represents a concrete task performed by an AsyncManager. Normally, you would subclass from this class, and override do_task(), to define the functionality you wish to have the task perform.

Inheritance diagram

Inheritance diagram of AsyncTask

__init__(param0: AsyncTask) → None
getState() → State

Returns the current state of the task.

Return type

State

isAlive() → bool

Returns true if the task is currently active or sleeping on some task chain, meaning that it will be executed in its turn, or false if it is not active. If the task has recently been removed while it is in the middle of execution, this will return false, because the task will not run again once it finishes.

getManager() → AsyncTaskManager

Returns the AsyncTaskManager that this task is active on. This will be NULL if the state is S_inactive.

Return type

AsyncTaskManager

remove() → bool

Removes the task from its active manager, if any, and makes the state S_inactive (or possible S_servicing_removed). This is a no-op if the state is already S_inactive.

setDelay(delay: float) → None

Specifies the amount of time, in seconds, by which this task will be delayed after it has been added to the AsyncTaskManager. At least the specified amount of time (and possibly more) will elapse before the task begins.

You may specify a delay of 0.0 to guarantee that the task will run in the next epoch following the one in which it is added.

Setting this value after the task has already been added will not affect the task’s wake time; it will only affect the task if it is re-added to the queue in the future, for instance if the task returns DS_again. However, see recalcWakeTime() if you wish to apply the delay effect immediately.

clearDelay() → None

Removes any delay specified for the task. The next time the task is added to the queue, it will run immediately. This does not affect the task’s wake time if it has already been added to the queue.

hasDelay() → bool

Returns true if a delay has been set for this task via setDelay(), or false otherwise.

getDelay() → float

Returns the delay value that has been set via set_delay, if any.

getWakeTime() → float

If this task has been added to an AsyncTaskManager with a delay in effect, this returns the time at which the task is expected to awaken. It has no meaning if the task has not yet been added to a queue, or if there was no delay in effect at the time the task was added.

If the task’s status is not S_sleeping, this returns 0.0.

recalcWakeTime() → None

If the task is currently sleeping on a task chain, this resets its wake time to the current time + getDelay(). It is as if the task had suddenly returned DS_again. The task will sleep for its current delay seconds before running again. This method may therefore be used to make the task wake up sooner or later than it would have otherwise.

If the task is not already sleeping, this method has no effect.

getStartTime() → float

Returns the time at which the task was started, according to the task manager’s clock.

It is only valid to call this if the task’s status is not S_inactive.

getElapsedTime() → float

Returns the amount of time that has elapsed since the task was started, according to the task manager’s clock.

It is only valid to call this if the task’s status is not S_inactive.

getStartFrame() → int

Returns the frame number at which the task was started, according to the task manager’s clock.

It is only valid to call this if the task’s status is not S_inactive.

getElapsedFrames() → int

Returns the number of frames that have elapsed since the task was started, according to the task manager’s clock.

It is only valid to call this if the task’s status is not S_inactive.

setName(name: str) → None
clearName() → None

Resets the task’s name to empty.

getNamePrefix() → str

Returns the initial part of the name, up to but not including any trailing digits following a hyphen or underscore.

getTaskId() → Integer

Returns a number guaranteed to be unique for each different AsyncTask object in the universe.

Return type

Integer

setTaskChain(chain_name: str) → None

Specifies the AsyncTaskChain on which this task will be running. Each task chain runs tasks independently of the others.

getTaskChain() → str

Returns the AsyncTaskChain on which this task will be running. Each task chain runs tasks independently of the others.

setSort(sort: int) → None

Specifies a sort value for this task. Within a given AsyncTaskManager, all of the tasks with a given sort value are guaranteed to be completed before any tasks with a higher sort value are begun.

To put it another way, two tasks might execute in parallel with each other only if they both have the same sort value. Tasks with a lower sort value are executed first.

This is different from the priority, which makes no such exclusion guarantees.

getSort() → int

Returns the task’s current sort value. See setSort().

setPriority(priority: int) → None

Specifies a priority value for this task. In general, tasks with a higher priority value are executed before tasks with a lower priority value (but only for tasks with the same sort value).

Unlike the sort value, tasks with different priorities may execute at the same time, if the AsyncTaskManager has more than one thread servicing tasks.

Also see AsyncTaskChain.setTimeslicePriority(), which changes the meaning of this value. In the default mode, when the timeslice_priority flag is false, all tasks always run once per epoch, regardless of their priority values (that is, the priority controls the order of the task execution only, not the number of times it runs). On the other hand, if you set the timeslice_priority flag to true, then changing a task’s priority has an effect on the number of times it runs.

getPriority() → int

Returns the task’s current priority value. See setPriority().

setDoneEvent(done_event: str) → None

Sets the event name that will be triggered when the task finishes. This should only be called before the task has been started, or after it has finished and before it is about to be restarted (i.e. when getState() returns S_inactive).

getDt() → float

Returns the amount of time elapsed during the task’s previous run cycle, in seconds.

getMaxDt() → float

Returns the maximum amount of time elapsed during any one of the task’s previous run cycles, in seconds.

getAverageDt() → float

Returns the average amount of time elapsed during each of the task’s previous run cycles, in seconds.

output(out: ostream) → None
static getClassType() → TypeHandle
Return type

TypeHandle

property state

Returns the current state of the task.

Return type

State

property alive

Returns true if the task is currently active or sleeping on some task chain, meaning that it will be executed in its turn, or false if it is not active. If the task has recently been removed while it is in the middle of execution, this will return false, because the task will not run again once it finishes.

Return type

bool

property manager

Returns the AsyncTaskManager that this task is active on. This will be NULL if the state is S_inactive.

Return type

AsyncTaskManager

property name

The name of this task.

Return type

string

property id

This is a number guaranteed to be unique for each different AsyncTask object in the universe.

Returns a number guaranteed to be unique for each different AsyncTask object in the universe.

Return type

Integer

property task_chain
Getter

Returns the AsyncTaskChain on which this task will be running. Each task chain runs tasks independently of the others.

Setter

Specifies the AsyncTaskChain on which this task will be running. Each task chain runs tasks independently of the others.

Return type

string

property sort
Getter

Returns the task’s current sort value. See setSort().

Setter

Specifies a sort value for this task. Within a given AsyncTaskManager, all of the tasks with a given sort value are guaranteed to be completed before any tasks with a higher sort value are begun.

To put it another way, two tasks might execute in parallel with each other only if they both have the same sort value. Tasks with a lower sort value are executed first.

This is different from the priority, which makes no such exclusion guarantees.

Return type

int

property priority
Getter

Returns the task’s current priority value. See setPriority().

Setter

Specifies a priority value for this task. In general, tasks with a higher priority value are executed before tasks with a lower priority value (but only for tasks with the same sort value).

Unlike the sort value, tasks with different priorities may execute at the same time, if the AsyncTaskManager has more than one thread servicing tasks.

Also see AsyncTaskChain.setTimeslicePriority(), which changes the meaning of this value. In the default mode, when the timeslice_priority flag is false, all tasks always run once per epoch, regardless of their priority values (that is, the priority controls the order of the task execution only, not the number of times it runs). On the other hand, if you set the timeslice_priority flag to true, then changing a task’s priority has an effect on the number of times it runs.

Return type

int

property done_event

Returns the event name that will be triggered when the future finishes. See setDoneEvent().

Getter

Returns the event name that will be triggered when the future finishes. See setDoneEvent().

Setter

Sets the event name that will be triggered when the task finishes. This should only be called before the task has been started, or after it has finished and before it is about to be restarted (i.e. when getState() returns S_inactive).

Return type

string

property dt

Returns the amount of time elapsed during the task’s previous run cycle, in seconds.

Return type

float

property max_dt

Returns the maximum amount of time elapsed during any one of the task’s previous run cycles, in seconds.

Return type

float

property average_dt

Returns the average amount of time elapsed during each of the task’s previous run cycles, in seconds.

Return type

float

enum DoneStatus
enumerator DS_done = 0

normal task completion

enumerator DS_cont = 1

run task again next epoch

enumerator DS_again = 2

start the task over from the beginning

enumerator DS_pickup = 3

run task again this frame, if frame budget allows

enumerator DS_exit = 4

stop the enclosing sequence

enumerator DS_pause = 5

pause, then exit (useful within a sequence)

enumerator DS_interrupt = 6

interrupt the task manager, but run task again

enumerator DS_await = 7

await a different task’s completion

enum State
enumerator S_inactive = 0
enumerator S_active = 1
enumerator S_servicing = 2
enumerator S_servicing_removed = 3

Still servicing, but wants removal from manager.

enumerator S_sleeping = 4
enumerator S_active_nested = 5

active within a sequence.

enumerator S_awaiting = 6

Waiting for a dependent task to complete