The RunTask modules defines one class realizing a coherent time task scheduler with a set of methods for the control of excution timing of a set of tasks.
Implements a coherent time task scheduler. The scheduling time used by RunTask is computed from the system time multiplying it by the speed factor (float) and setting epoch (float, unit: second) as the beginning of time. The result is quantized by tick value (float, unit: second) to obtain the scheduling time.
Timing generator. Set a periodic timing. The timing period can be aligned to a reference time. The task execution can be a single shot, a given number of times or forever.
period: float (seconds) or tuple (numerator seconds, denominator seconds), time elapse between task runs. If tuple, the period is a fractional number: the first is the numerator, the second is the denominator.
phase: float (seconds), the time offset from which an integer number of periods are added to obtain the next task run time.
runs: integer, number of task runs. If -1, run task forever.
The first task run happens when the RunTask time reaches the next integer multiple of period plus phase.
Timing generator. Set a periodic timing with immediate start. The task execution can be a single shot, a given number of times or forever.
period: float (seconds) or tuple (numerator seconds, denominator seconds), time elapse between task runs. If tuple, the period is a fractional number: the first is the numerator, the second is the denominator.
runs: integer, number of task runs. If -1, run task forever.
Task run is aligned with a multiple of time tick.
Return the number of runs left excluding the current one. If the task is run forever, return -1 .
Start execution of registered tasks. If join is False, start returns immediately to the calling program. If join is True, start returns only when stop is called by a registered task.
Stop execution of registered tasks.
Register a task to be run.
target: callable, a function, a class method, the task to be run.
args: list/tuple, function positional arguments.
kargs: dictionary, function keyword arguments.
timing: a call to one of the timing methods, periodic, etc.
worker: at present, not used.
All times are in unix format, a float whose units are seconds from the beginning of epoch.
Return current task information.
Return pattern (id, runtime, run_count, task_args)
id: integer, the task identifier, it is the order of registration starting from zero.
runtime: float, the nominal task run time.
run_count: integer, number of current run, first run is #1.
task_args: tuple, all args saved by task method, (target, args, kargs, timing, timing_args, worker). timing_args is the tuple of the arguments given to the timing method specified in the task method call.
Timing generator. Set an execution timing aligned to the first period and repeat period with a random unform distribution between period_min and period_max. The task execution can be a single shot, a given number of times or forever.
period_min: float (seconds), minimum of period execution time.
period_max: float (seconds), maximum of period execution time.
runs: integer, number of task runs. If -1, run task forever.
Task run is aligned with a multiple of time tick.