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 . If called from inside the task itself, do not specify any target (target=None). If called from another thread, specify the target of the wanted task.
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.
Case 1: target is a callable, a function or a class method.
target: when the run time comes, target is called.
arguments: (args,kargs) where args are the function positional arguments (list or tuple) and kargs are the function keyword arguments (dictionary).
Case 2: target is a threading Event.
target: when the run time comes, the target flag is set or cleared.
arguments: boolean, if true, the target flag is set. If false, the target flag is cleared.
Case 3: target is a threading Lock, a Semaphore or a BoundedSemaphore.
target: when the run time comes, the target object is acquired or released.
arguments: boolean, if true, the target object is acquired in non-bloking mode. If false, the target object is released.
Common arguments
timing: a call to one of the timing generators, periodic, etc.
worker: at present, not used.
Return information about a task registered into Runtask. If called from inside the task itself, do not specify any target (target=None). If called from another thread, specify the target of the wanted task.
Return pattern (id, last_runtime, run_count, task_args)
id: integer, the task identifier, it is the order of registration starting from zero.
last_runtime: float, the last 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.