gvalkov/python-evdev

Asyncio Exception async for' received an object from __aiter__ that does not implement __anext__: generator

wes8ty opened this issue · 3 comments

Has anybody had this issue running the example asyncio code. I am using Python 3.9.

self.__home_btn = InputDevice("/dev/input/homebtn")

async def read_btn(self) -> None:
    async for ev in self.__home_btn.async_read_loop():
        if ev.code == ecodes.KEY_HOME and 1 == ev.value:
            self.__log.info("Button Pressed")

asyncio.run(self.read_btn())

'async for' received an object from __aiter__ that does not implement __anext__: generator

This is what I just used to try to reproduce it standalone without having to integrate it into a class:

from evdev import InputDevice, ecodes, list_devices
import asyncio

__home_btn = InputDevice(list_devices()[0])

async def read_btn() -> None:
    async for ev in __home_btn.async_read_loop():
        if ev.code == ecodes.KEY_HOME and 1 == ev.value:
            print("Button Pressed")

asyncio.run(read_btn())

It just blocks forever. If I select my keyboard as InputDevice and print all ev objects, it will print the events

Tested on Python 3.10.4, evdev 1.5.0

I found out why. I had an old version of the evdev 0.7.0 installed for some reason. I installed 1.5.0 and it works! Thanks so much.