I have a python-raspberryPi project that needs some Asynch IO so it can do multiple read/action and not get blocked. One action is reading (distance) values from a Bluetooth device. I have a script that uses pexpect and gatttool with send/expect wrapped up in try-except that works standalone. However the BLE device is a bit flaky. It takes 3-5sec for pexpect-gatttool to respond to a ‘connect’, a few seconds to wait between data retrieval, etc. It can timeout about 5-10% of the time, basically requiring killing the pexpect and restarting it (5sec or so). This sort of IO bound task is classic for running async threads.
I found the Trio library for python which seems to provide a nice encapsulation and abstraction of the whole async thing but have yet to find and references or examples of using Trio with pexpect.
Has anyone tried using trio with pexpect?
I see from docs that p.expect(cmd, async=True) will return an asyncio coroutine, but nothing with trio?