Timers

Provides a simple implementation of timers run inside asyncio event loops.

class TimerDelayPolicy(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

An enumeration of supported policies for when the timer function takes longer on each tick than the given timer interval.

CANCEL = 1
DEFAULT = 0
class VirtualClock[source]

Provide a virtual clock for an asyncio event loop which makes timing-based tests deterministic and instantly completed.

patch_loop()[source]

Override some methods of the current event loop so that sleep instantly returns while proceeding the virtual clock.

virtual_time() float[source]

Return the current virtual time.

create_timer(cb: Callable[[float], Union[Generator[Any, None, None], Coroutine[Any, Any, None]]], interval: float, delay_policy: aiotools.timer.TimerDelayPolicy = TimerDelayPolicy.DEFAULT, loop: Optional[asyncio.events.AbstractEventLoop] = None) _asyncio.Task[source]

Schedule a timer with the given callable and the interval in seconds. The interval value is also passed to the callable. If the callable takes longer than the timer interval, all accumulated callable’s tasks will be cancelled when the timer is cancelled.

Parameters

cb – TODO - fill argument descriptions

Returns

You can stop the timer by cancelling the returned task.