Task¶
A task is something that needs to be done. Tasks come in a variety of flavors:
OneShotTask
- do something onceOneShotDeleteTask
- do something once, then delete the task objectRecurringTask
- do something at regular intervals
Every derived class of one of these classes must provide a process_task method which will be called at the next opportunity available to the application. All task processing is expected to be cooperative, which means that it must be written so that it is cognizant that other tasks may also be waiting for a chance to be processed.
Tasks are installed when they should be scheduled for processing, may be suspended or removed from scheduling, and then may be resumed or re-installed.
Singleton Task Manager¶
All operations involving tasks are directed to a single instance of
TaskManager
or an instance of a derived class. If the developer
creates a derived class of TaskManager
and an instance of it before
the core.run()
function is called, that instance will be used to
schedule tasks and return the next task to process.
Globals¶
-
task.
_task_manager
¶ This is a long line of text.
-
task.
_unscheduled_tasks
¶ This is a long line of text.
Functions¶
-
task.
OneShotFunction
(fn, *args, **kwargs)¶ Parameters: - fn – function to schedule
- args – function to schedule
- kwargs – function to schedule
This is a long line of text.
-
task.
FunctionTask
(fn, *args, **kwargs)¶ Parameters: fn – function to update This is a long line of text.
-
task.
RecurringFunctionTask
(interval, fn, *args, **kwargs)¶ Parameters: fn – function to update This is a long line of text.
Function Decorators¶
-
task.
recurring_function
(interval)¶ Parameters: interval – interval to call the function This function will return a decorator which will wrap a function in a task object that will be called at regular intervals and can also be called as a function. For example:
@recurring_function(5000) def my_ping(arg=None): print "my_ping", arg
The my_ping object is a task that can be installed, suspended, and resumed like any other task. This is installed to run every 5s and will print:
my_ping None
And can also be called as a regular function with parameters, so calling my_ping(“hello”) will print:
my_ping hello
Classes¶
-
class
task.
_Task
¶ This is a long line of text.
-
install_task
(when=None)¶ Parameters: when (float) – time task should be processed This is a long line of text.
-
process_task
()¶ Parameters: when (float) – time task should be processed This is a long line of text.
-
suspend_task
()¶ Parameters: when (float) – time task should be processed This is a long line of text.
-
resume_task
()¶ Parameters: when (float) – time task should be processed This is a long line of text.
-
-
class
task.
OneShotTask
¶ This is a long line of text.
-
class
task.
OneShotDeleteTask
¶ This is a long line of text.
-
class
task.
RecurringTask
¶ This is a long line of text.
-
class
task.
TaskManager
¶ This is a long line of text.
-
install_task
(task)¶ Parameters: task – task to be installed This is a long line of text.
-
suspend_task
(task)¶ Parameters: task – task to be suspended This is a long line of text.
-
resume_task
(task)¶ Parameters: task – task to be resumed This is a long line of text.
-
get_next_task
()¶ This is a long line of text.
-
process_task
()¶ This is a long line of text.
-