ainput - asynchronous user input libraries based on uasyncio

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
shawwwn
Posts: 16
Joined: Tue Feb 06, 2018 5:22 am

ainput - asynchronous user input libraries based on uasyncio

Post by shawwwn » Tue Feb 06, 2018 5:58 am

I have been experimenting MicroPython on my ESP8266 for the past few days.
I needed to do some multitasking for my project however it seems there is no easy way to do it.
uasyncio turns out to be a great alternative to threads, however it blocks user input when an event loop is running.
I wrote a set of libraries that enables user input even when there are tasks running in the background.

https://github.com/shawwwn/micropython-ainput

uaioinput - Just like input() except it can be run in an event loop
uaiorepl - Crude simulation of REPL console in an event loop
uaiotelnet - Telnet server that runs in an event loop. Adapted from https://github.com/cpopp/MicroTelnetServer
uaiowebrepl - Modified WebREPL server that runs in an event loop

NOTE:
uaiotelnet /uaiowebrepl must run together with uaioinput/uaiorepl otherwise user input would still be blocked.
Should be able to work on ESP32 , but I'm still waiting for my board to arrive.

cefn
Posts: 230
Joined: Tue Aug 09, 2016 10:58 am

Re: ainput - asynchronous user input libraries based on uasyncio

Post by cefn » Tue Feb 06, 2018 8:13 pm

That's really exciting and interesting.

Is there a technical reason uaiorepl can't be wired to the 'real' REPL, anyone?

shawwwn
Posts: 16
Joined: Tue Feb 06, 2018 5:22 am

Re: ainput - asynchronous user input libraries based on uasyncio

Post by shawwwn » Wed Feb 07, 2018 6:00 am

cefn wrote:
Tue Feb 06, 2018 8:13 pm
That's really exciting and interesting.

Is there a technical reason uaiorepl can't be wired to the 'real' REPL, anyone?
It seems there are multiple places in the source code that would block/deny user input when something is running in repl.
However, the underlying issue here I think is the design decision residing with MicroPython.
The repl execution is running as the main task, it means MicroPython won't take any input until the execution has returned.
There is no simple way to get around this, I'm afraid.

Post Reply