Poller

This module provides a general framework and mechanism for polling.

class Poller(poll_model: PollModel[PollRequestT, PollResponseT], poll_rate: float = 1.0)[source]

A generic hardware polling mechanism.

start_polling() None[source]

Start polling.

stop_polling() None[source]

Stop polling.

class PollModel[source]

Abstract base class for a polling model.

get_request() PollRequestT[source]

Return the polling request to be executed at the next poll.

This is a hook called by the poller each polling loop, to obtain instructions on what it should do on the next poll.

Returns:

attribute request to be executed at the next poll.

Raises:

NotImplementedError – because this class is abstract

poll(poll_request: PollRequestT) PollResponseT[source]

Perform a single poll.

This is a hook called by the poller each polling loop.

Parameters:

poll_request – specification of what is to be done on the poll. It might, for example, contain a list of reads and writes to be executed.

Returns:

responses from this poll

Raises:

NotImplementedError – because this class is abstract.

polling_started() None[source]

Respond to polling having started.

This is a hook called by the poller when it starts polling.

polling_stopped() None[source]

Respond to polling having stopped.

This is a hook called by the poller when it stops polling.

poll_succeeded(poll_response: PollResponseT) None[source]

Handle successful completion of a poll.

This is a hook called by the poller upon the successful completion of a poll.

Parameters:

poll_response – The response to the poll, containing for example any values read.

poll_failed(exception: Exception) None[source]

Respond to an exception being raised by a poll attempt.

This is a hook called by the poller when an exception occurs. The polling loop itself never raises exceptions. It catches everything and simply calls this hook to let the polling model know what it caught.

Parameters:

exception – the exception that was raised by a recent poll attempt.

class PollRequestT

Type variable for object specifying what the poller should do next poll.

alias of TypeVar(‘PollRequestT’)

class PollResponseT

Type variable for object containing the result of the previous poll.

alias of TypeVar(‘PollResponseT’)