AsyncTaskManager¶
from acron.core import AsyncTaskManager
- class AsyncTaskManager¶
Bases:
Bases:
TypedReferenceCount,NamableA class to manage a loose queue of isolated tasks, which can be performed either synchronously (in the foreground thread) or asynchronously (by a background thread).
The AsyncTaskManager is actually a collection of
AsyncTaskChains, each of which maintains a list of tasks. Each chain can be either foreground or background (it may run only in the main thread, or it may be serviced by one or more background threads). SeeAsyncTaskChainfor more information.If you do not require background processing, it is perfectly acceptable to create only one
AsyncTaskChain, which runs in the main thread. This is a common configuration.Inheritance diagram
digraph inheritanceec047775af { bgcolor=transparent; rankdir=BT; size="8.0, 12.0"; "AsyncTaskManager" [URL="acron.core.AsyncTaskManager.html#acron.core.AsyncTaskManager",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "TypedReferenceCount" -> "AsyncTaskManager" [arrowsize=0.75,style=""]; "Namable" -> "AsyncTaskManager" [arrowsize=0.75,style=""]; "DTOOL_SUPER_BASE" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style=""]; "Namable" [URL="acron.core.Namable.html#acron.core.Namable",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "Namable" [arrowsize=0.75,style=""]; "ReferenceCount" [URL="acron.core.ReferenceCount.html#acron.core.ReferenceCount",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "ReferenceCount" [arrowsize=0.75,style=""]; "TypedObject" [URL="acron.core.TypedObject.html#acron.core.TypedObject",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "TypedObject" [arrowsize=0.75,style=""]; "TypedReferenceCount" [URL="acron.core.TypedReferenceCount.html#acron.core.TypedReferenceCount",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "TypedObject" -> "TypedReferenceCount" [arrowsize=0.75,style=""]; "ReferenceCount" -> "TypedReferenceCount" [arrowsize=0.75,style=""]; }- __init__()¶
- property active_tasks AsyncTaskCollection¶
Returns the set of tasks that are active (and not sleeping) on the task manager, at the time of the call.
- add()¶
Adds the indicated task to the active queue. It is an error if the task is already added to this or any other active queue.
- cleanup()¶
Stops all threads and messily empties the task list. This is intended to be called on destruction only.
- property clock ClockObject¶
- Getter
Returns the clock pointer used within the
AsyncTaskManager. Seeset_clock().- Setter
Replaces the clock pointer used within the
AsyncTaskManager. This is used to control when tasks with a set_delay() specified will be scheduled. It can also be ticked automatically each epoch, if set_tick_clock() is true.The default is the global clock pointer.
- find_task()¶
Returns the first task found with the indicated name, or NULL if there is no task with the indicated name.
If there are multiple tasks with the same name, returns one of them arbitrarily.
- find_task_chain()¶
Searches a new
AsyncTaskChainof the indicated name and returns it if it exists, or NULL otherwise.
- find_tasks()¶
Returns the list of tasks found with the indicated name.
- find_tasks_matching()¶
Returns the list of tasks found whose name matches the indicated glob pattern, e.g. “my_task_*”.
- get_active_tasks()¶
Returns the set of tasks that are active (and not sleeping) on the task manager, at the time of the call.
- static get_class_type()¶
- get_clock()¶
Returns the clock pointer used within the
AsyncTaskManager. Seeset_clock().
- static get_global_ptr()¶
Returns a pointer to the global
AsyncTaskManager. This is theAsyncTaskManagerthat most code should use for queueing tasks and suchlike.
- get_next_wake_time()¶
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_task_chains()¶
Returns the number of different task chains.
- get_num_tasks()¶
Returns the number of tasks that are currently active or sleeping within the task manager.
- get_sleeping_tasks()¶
Returns the set of tasks that are sleeping (and not active) on the task manager, at the time of the call.
- get_task_chain()¶
Returns the nth task chain.
- get_tasks()¶
Returns the set of tasks that are active or sleeping on the task manager, at the time of the call.
- has_task()¶
Returns true if the indicated task has been added to this
AsyncTaskManager, false otherwise.
- make_task_chain()¶
Creates a new
AsyncTaskChainof the indicated name and stores it within theAsyncTaskManager. If a task chain with this name already exists, returns it instead.Creates a new threaded
AsyncTaskChainof the indicated name and stores it within theAsyncTaskManager. If a task chain with this name already exists, returns it instead.
- property next_wake_time float¶
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.
- output()¶
- poll()¶
Runs through all the tasks in the task list, once, if the task manager 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.
- remove()¶
Removes the indicated task from the active queue. Returns true if the task is successfully removed, or false if it wasn’t there.
Removes all of the tasks in the
AsyncTaskCollection. Returns the number of tasks removed.
- remove_task_chain()¶
Removes the
AsyncTaskChainof the indicated name. If the chain still has tasks, this will block until all tasks are finished.Returns true if successful, or false if the chain did not exist.
- set_clock()¶
Replaces the clock pointer used within the
AsyncTaskManager. This is used to control when tasks with a set_delay() specified will be scheduled. It can also be ticked automatically each epoch, if set_tick_clock() is true.The default is the global clock pointer.
- property sleeping_tasks AsyncTaskCollection¶
Returns the set of tasks that are sleeping (and not active) on the task manager, at the time of the call.
- start_threads()¶
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.
- stop_threads()¶
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()orstart_threads()is later called.
- property tasks AsyncTaskCollection¶
Returns the set of tasks that are active or sleeping on the task manager, at the time of the call.
- wait_for_tasks()¶
Blocks until the task list is empty.
- write()¶