AsyncTask

from panda3d.core import 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

DSAgain = 2
DSAwait = 7
DSCont = 1
DSDone = 0
DSExit = 4
DSInterrupt = 6
DSPause = 5
DSPickup = 3
DS_again = 2
DS_await = 7
DS_cont = 1
DS_done = 0
DS_exit = 4
DS_interrupt = 6
DS_pause = 5
DS_pickup = 3
SActive = 1
SActiveNested = 5
SAwaiting = 6
SInactive = 0
SServicing = 2
SServicingRemoved = 3
SSleeping = 4
S_active = 1
S_active_nested = 5
S_awaiting = 6
S_inactive = 0
S_servicing = 2
S_servicing_removed = 3
S_sleeping = 4
__init__(*args, **kwargs)
alive
average_dt
clearDelay()

C++ Interface: clear_delay(const AsyncTask self)

/**
  • 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.

*/

clearName()

C++ Interface: clear_name(const AsyncTask self)

/**
  • Resets the task’s name to empty.

*/

clear_delay()

C++ Interface: clear_delay(const AsyncTask self)

/**
  • 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.

*/

clear_name()

C++ Interface: clear_name(const AsyncTask self)

/**
  • Resets the task’s name to empty.

*/

done_event

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

dt
getAverageDt()

C++ Interface: get_average_dt(AsyncTask self)

/**
  • Returns the average amount of time elapsed during each of the task’s

  • previous run cycles, in seconds.

*/

getClassType()

C++ Interface: get_class_type()

getDelay()

C++ Interface: get_delay(AsyncTask self)

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

*/

getDt()

C++ Interface: get_dt(AsyncTask self)

/**
  • Returns the amount of time elapsed during the task’s previous run cycle, in

  • seconds.

*/

getElapsedFrames()

C++ Interface: get_elapsed_frames(AsyncTask self)

/**
  • 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.

*/

getElapsedTime()

C++ Interface: get_elapsed_time(AsyncTask self)

/**
  • 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.

*/

getManager()

C++ Interface: get_manager(AsyncTask self)

/**
  • Returns the AsyncTaskManager that this task is active on. This will be

  • NULL if the state is S_inactive.

*/

getMaxDt()

C++ Interface: get_max_dt(AsyncTask self)

/**
  • Returns the maximum amount of time elapsed during any one of the task’s

  • previous run cycles, in seconds.

*/

getNamePrefix()

C++ Interface: get_name_prefix(AsyncTask self)

/**
  • Returns the initial part of the name, up to but not including any trailing

  • digits following a hyphen or underscore.

*/

getPriority()

C++ Interface: get_priority(AsyncTask self)

/**
  • Returns the task’s current priority value. See set_priority().

*/

getSort()

C++ Interface: get_sort(AsyncTask self)

/**
  • Returns the task’s current sort value. See set_sort().

*/

getStartFrame()

C++ Interface: get_start_frame(AsyncTask self)

/**
  • 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.

*/

getStartTime()

C++ Interface: get_start_time(AsyncTask self)

/**
  • 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.

*/

getState()

C++ Interface: get_state(AsyncTask self)

/**
  • Returns the current state of the task.

*/

getTaskChain()

C++ Interface: get_task_chain(AsyncTask self)

/**
  • Returns the AsyncTaskChain on which this task will be running. Each task

  • chain runs tasks independently of the others.

*/

getTaskId()

C++ Interface: get_task_id(AsyncTask self)

/**
  • Returns a number guaranteed to be unique for each different AsyncTask

  • object in the universe.

*/

getWakeTime()

C++ Interface: get_wake_time(AsyncTask self)

/**
  • 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.

*/

get_average_dt()

C++ Interface: get_average_dt(AsyncTask self)

/**
  • Returns the average amount of time elapsed during each of the task’s

  • previous run cycles, in seconds.

*/

get_class_type()

C++ Interface: get_class_type()

get_delay()

C++ Interface: get_delay(AsyncTask self)

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

*/

get_dt()

C++ Interface: get_dt(AsyncTask self)

/**
  • Returns the amount of time elapsed during the task’s previous run cycle, in

  • seconds.

*/

get_elapsed_frames()

C++ Interface: get_elapsed_frames(AsyncTask self)

/**
  • 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.

*/

get_elapsed_time()

C++ Interface: get_elapsed_time(AsyncTask self)

/**
  • 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.

*/

get_manager()

C++ Interface: get_manager(AsyncTask self)

/**
  • Returns the AsyncTaskManager that this task is active on. This will be

  • NULL if the state is S_inactive.

*/

get_max_dt()

C++ Interface: get_max_dt(AsyncTask self)

/**
  • Returns the maximum amount of time elapsed during any one of the task’s

  • previous run cycles, in seconds.

*/

get_name_prefix()

C++ Interface: get_name_prefix(AsyncTask self)

/**
  • Returns the initial part of the name, up to but not including any trailing

  • digits following a hyphen or underscore.

*/

get_priority()

C++ Interface: get_priority(AsyncTask self)

/**
  • Returns the task’s current priority value. See set_priority().

*/

get_sort()

C++ Interface: get_sort(AsyncTask self)

/**
  • Returns the task’s current sort value. See set_sort().

*/

get_start_frame()

C++ Interface: get_start_frame(AsyncTask self)

/**
  • 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.

*/

get_start_time()

C++ Interface: get_start_time(AsyncTask self)

/**
  • 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.

*/

get_state()

C++ Interface: get_state(AsyncTask self)

/**
  • Returns the current state of the task.

*/

get_task_chain()

C++ Interface: get_task_chain(AsyncTask self)

/**
  • Returns the AsyncTaskChain on which this task will be running. Each task

  • chain runs tasks independently of the others.

*/

get_task_id()

C++ Interface: get_task_id(AsyncTask self)

/**
  • Returns a number guaranteed to be unique for each different AsyncTask

  • object in the universe.

*/

get_wake_time()

C++ Interface: get_wake_time(AsyncTask self)

/**
  • 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.

*/

hasDelay()

C++ Interface: has_delay(AsyncTask self)

/**
  • Returns true if a delay has been set for this task via set_delay(), or

  • false otherwise.

*/

has_delay()

C++ Interface: has_delay(AsyncTask self)

/**
  • Returns true if a delay has been set for this task via set_delay(), or

  • false otherwise.

*/

id

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

isAlive()

C++ Interface: is_alive(AsyncTask self)

/**
  • 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.

*/

is_alive()

C++ Interface: is_alive(AsyncTask self)

/**
  • 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.

*/

manager
max_dt
name

The name of this task.

output()

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

/**

*/

priority
recalcWakeTime()

C++ Interface: recalc_wake_time(const AsyncTask self)

/**
  • If the task is currently sleeping on a task chain, this resets its wake

  • time to the current time + get_delay(). 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.

*/

recalc_wake_time()

C++ Interface: recalc_wake_time(const AsyncTask self)

/**
  • If the task is currently sleeping on a task chain, this resets its wake

  • time to the current time + get_delay(). 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.

*/

remove()

C++ Interface: remove(const AsyncTask self)

/**
  • 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.

  • If the task is a coroutine that is currently awaiting a future, this will

  • fail, but see also cancel().

*/

setDelay()

C++ Interface: set_delay(const AsyncTask self, double delay)

/**
  • 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 recalc_wake_time() if you wish to apply the delay effect immediately.

*/

setDoneEvent()

C++ Interface: set_done_event(const AsyncTask self, str done_event)

/**
  • 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 get_state()

  • returns S_inactive).

*/

setName()

C++ Interface: set_name(const AsyncTask self, str name)

/**

*/

setPriority()

C++ Interface: set_priority(const AsyncTask self, int priority)

/**
  • 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::set_timeslice_priority(), 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.

*/

setSort()

C++ Interface: set_sort(const AsyncTask self, int sort)

/**
  • 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.

*/

setTaskChain()

C++ Interface: set_task_chain(const AsyncTask self, str chain_name)

/**
  • Specifies the AsyncTaskChain on which this task will be running. Each task

  • chain runs tasks independently of the others.

*/

set_delay()

C++ Interface: set_delay(const AsyncTask self, double delay)

/**
  • 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 recalc_wake_time() if you wish to apply the delay effect immediately.

*/

set_done_event()

C++ Interface: set_done_event(const AsyncTask self, str done_event)

/**
  • 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 get_state()

  • returns S_inactive).

*/

set_name()

C++ Interface: set_name(const AsyncTask self, str name)

/**

*/

set_priority()

C++ Interface: set_priority(const AsyncTask self, int priority)

/**
  • 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::set_timeslice_priority(), 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.

*/

set_sort()

C++ Interface: set_sort(const AsyncTask self, int sort)

/**
  • 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.

*/

set_task_chain()

C++ Interface: set_task_chain(const AsyncTask self, str chain_name)

/**
  • Specifies the AsyncTaskChain on which this task will be running. Each task

  • chain runs tasks independently of the others.

*/

sort
state
task_chain
upcastToAsyncFuture()

C++ Interface: upcast_to_AsyncFuture(const AsyncTask self)

upcast from AsyncTask to AsyncFuture

upcastToNamable()

C++ Interface: upcast_to_Namable(const AsyncTask self)

upcast from AsyncTask to Namable

upcast_to_AsyncFuture()

C++ Interface: upcast_to_AsyncFuture(const AsyncTask self)

upcast from AsyncTask to AsyncFuture

upcast_to_Namable()

C++ Interface: upcast_to_Namable(const AsyncTask self)

upcast from AsyncTask to Namable