Implements multitasking with scheduling and some performance logging. More...
Public Member Functions | |
def | __init__ (self, run_fun, name="NoName", priority=0, period=None, profile=False, trace=False) |
Initialize a task object so it may be run by the scheduler. More... | |
bool | schedule (self) |
bool | ready (self) |
def | reset_profile (self) |
! This method resets the variables used for execution time profiling. More... | |
def | get_trace (self) |
def | go (self) |
def | __repr__ (self) |
Public Attributes | |
name | |
The name of the task, hopefully a short and descriptive string. | |
priority | |
The task's priority, an integer with higher numbers meaning higher priority. | |
period | |
The period, in milliseconds, between runs of the task's run() method. More... | |
go_flag | |
Flag which is set true when the task is ready to be run by the scheduler. | |
Implements multitasking with scheduling and some performance logging.
This class implements behavior common to tasks in a cooperative multitasking system which runs in MicroPython. The ability to be scheduled on the basis of time or an external software trigger or interrupt is implemented, state transitions can be recorded, and run times can be profiled. The user's task code must be implemented in a generator which yields the state (and the CPU) after it has run for a short and bounded period of time.
Examples
def cotask.Task.__init__ | ( | self, | |
run_fun, | |||
name = "NoName" , |
|||
priority = 0 , |
|||
period = None , |
|||
profile = False , |
|||
trace = False |
|||
) |
Initialize a task object so it may be run by the scheduler.
This method initializes a task object, saving copies of constructor parameters and preparing an empty dictionary for states. @param run_fun The function which implements the task's code. It must be a generator which yields the current state. @param name The name of the task, by default @c NoName. This should be overridden with a more descriptive name by the programmer. @param priority The priority of the task, a positive integer with higher numbers meaning higher priority (default 0) @param period The time in milliseconds between runs of the task if it's run by a timer or @c None if the task is not run by a timer. The time can be given in a @c float or @c int; it will be converted to microseconds for internal use by the scheduler. @param profile Set to @c True to enable run-time profiling @param trace Set to @c True to generate a list of transitions between states. @b Note: This slows things down and allocates memory.
def cotask.Task.reset_profile | ( | self | ) |
! This method resets the variables used for execution time profiling.
This method is also used by init
() to create the variables.
cotask.Task.period |