API

The API consist of Timer class, which object represents asynchronous timer.

class atimer.Timer(interval: float, shift: float = 0.0)[source]

Timer based on Linux timerfd interface.

Timer object is a Python asynchronous coroutine. It waits for timer expiration. An awaited coroutine returns number of timer expirations.

The number of expirations is usually 1 until timer overrun happens. Refer to POSIX documentation for definition of the timer overrun.

Shift time value, moves the edge of time interval by the specified value. The value shall be at least 0 seconds, and less than the interval. Contructor of the timer raises value error for invalid shift value.

For interval 0.25 second, and shift 0.0 second, timer will wake up at times like:

1548799590.000
1548799590.250
1548799590.500
1548799590.750
1548799591.000

Changing shift to 0.02 second, timer will wake up at time like:

1548799590.020
1548799590.270
1548799590.520
1548799590.770
1548799591.020
Parameters:
  • interval – Interval, in seconds, at which the timer expires.

  • shift – Shift edge of the interval by specified time, in seconds.

close() None[source]

Stop and disarm the timer.

start() None[source]

Arm the timer.