Schedulers
pamiq_core.utils.schedulers.Scheduler ¶
Bases: ABC
Abstract base class for schedulers.
Schedulers periodically execute registered callbacks based on specific conditions defined by subclasses. The base class provides functionality for managing callbacks.
Initialize the scheduler.
PARAMETER | DESCRIPTION |
---|---|
callbacks
|
Optional iterable of callback functions to register or callback.
TYPE:
|
Source code in src/pamiq_core/utils/schedulers.py
register_callback ¶
Register a new callback function.
PARAMETER | DESCRIPTION |
---|---|
callback
|
The callback function to register.
TYPE:
|
remove_callback ¶
Remove a registered callback function.
PARAMETER | DESCRIPTION |
---|---|
callback
|
The callback function to remove.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the callback is not registered. |
Source code in src/pamiq_core/utils/schedulers.py
is_available
abstractmethod
¶
Check if the scheduler should execute callbacks now.
RETURNS | DESCRIPTION |
---|---|
bool
|
True if callbacks should be executed, False otherwise. |
update
abstractmethod
¶
Check if callbacks should be executed and run them if so.
This method should be called regularly to check if execution conditions are met.
Source code in src/pamiq_core/utils/schedulers.py
pamiq_core.utils.schedulers.TimeIntervalScheduler ¶
Bases: Scheduler
Scheduler that executes callbacks at specified time intervals.
This scheduler triggers callbacks when a specified amount of time has elapsed since the last execution.
Initialize the time interval scheduler.
PARAMETER | DESCRIPTION |
---|---|
interval
|
Time interval in seconds between executions.
TYPE:
|
callbacks
|
Optional iterable of callback functions to register.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If interval is negative. |
Source code in src/pamiq_core/utils/schedulers.py
is_available ¶
Check if the specified time interval has elapsed.
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the time interval has elapsed, False otherwise. |
Source code in src/pamiq_core/utils/schedulers.py
update ¶
Check if the time interval has elapsed and execute callbacks if so.
Updates the previous execution time after callbacks are executed.
Source code in src/pamiq_core/utils/schedulers.py
pamiq_core.utils.schedulers.StepIntervalScheduler ¶
Bases: Scheduler
Scheduler that executes callbacks after a specified number of steps.
This scheduler triggers callbacks when a specified number of steps have been completed since the last execution.
Initialize the step interval scheduler.
PARAMETER | DESCRIPTION |
---|---|
interval
|
Number of steps between executions.
TYPE:
|
callbacks
|
Optional iterable of callback functions to register.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If interval is not positive. |
Source code in src/pamiq_core/utils/schedulers.py
is_available ¶
Check if the specified number of steps has been reached.
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the step interval has been reached, False otherwise. |
Source code in src/pamiq_core/utils/schedulers.py
update ¶
Increment step counter, execute callbacks if interval is reached.
Resets the step counter after callbacks are executed.