Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RFC asyncio: efficiently polling devices #2664

@peterhinch

Description

@peterhinch

A common situation when interfacing hardware is the case where a device which is normally not ready needs to be polled. One solution is along the lines of

async def poll(device):
    while True:
        if device.ready():
            device.handle_data()
        yield

This works but has a high worst case latency. If there are N coroutines each with a maximum latency of T between yield statements, an interval of up to NT will exist between calls to device.ready(). This can be reduced to T if there is a way to delegate the polling to the scheduler. In other words to provide a facility to schedule on an event (cf the Poller class in my scheduler).
Any comments on ways to achieve this with uasyncio? Perhaps there's a solution which I've missed.

To anyone interested I've ported my classes for debounced switches and pushbuttons to asyncio and plan to extend this to other drivers. Preliminary code and docs here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, new feature implementations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions