|
| | __init__ (self, run_fun, name="NoName", priority=0, period=None, profile=False, trace=False, shares=()) |
| | Initialize a task object so it may be run by the scheduler.
|
| bool | schedule (self) |
| | This method is called by the scheduler; it attempts to run this task.
|
| bool | ready (self) |
| | This method checks if the task is ready to run.
|
| | set_period (self, new_period) |
| | This method sets the period between runs of the task to the given number of milliseconds, or None if the task is triggered by calls to go() rather than time.
|
| | reset_profile (self) |
| | This method resets the variables used for execution time profiling.
|
| | get_trace (self) |
| | This method returns a string containing the task's transition trace.
|
| | go (self) |
| | Method to set a flag so that this task indicates that it's ready to run.
|
| | __repr__ (self) |
| | This method converts the task to a string for diagnostic use.
|
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.
Example:
def task1_fun ():
'''! This function switches states repeatedly for no reason '''
state = 0
while True:
if state == 0:
state = 1
elif state == 1:
state = 0
yield (state)
task1 =
cotask.Task (task1_fun, name =
'Task 1', priority = 1,
period = 500, profile = True, trace = True)
cotask.task_list.append (task1)
while True:
cotask.task_list.pri_sched ()
Implements multitasking with scheduling and some performance logging.
Definition at line 66 of file cotask.py.
| bool cotask.Task.ready |
( |
| self | ) |
|
This method checks if the task is ready to run.
If the task runs on a timer, this method checks what time it is; if not, this method checks the flag which indicates that the task is ready to go. This method may be overridden in descendent classes to implement some other behavior.
Definition at line 197 of file cotask.py.
| bool cotask.Task.schedule |
( |
| self | ) |
|
This method is called by the scheduler; it attempts to run this task.
If the task is not yet ready to run, this method returns False immediately; if this task is ready to run, it runs the task's generator up to the next yield() and then returns True.
- Returns
True if the task ran or False if it did not
Definition at line 143 of file cotask.py.