dwhall / farc

Framework for state machines with run-to-completion concurrency using asyncio. Python 3.4 or later
MIT License
28 stars 6 forks source link

Interactive Example with Asynchronous console input #5

Open MiMiMeowMeow opened 5 years ago

MiMiMeowMeow commented 5 years ago

First of all, great work porting over QP to Python.

I was trying to make an interactive program similar to hsm_test.py but the TimeEvent's don't seem to work. I'm guessing that input('\tEvent --> ') call is blocking and those events are never processed.
I saw that this project has an asynchronous equivalent to input. https://github.com/vxgmichel/aioconsole

I'm pretty new to Asynchronous programming so I'm wondering if someone would post an example using this package so I can get interactivity with the TimeEvents.

Thanks!

dwhall commented 5 years ago

You're right that input() blocks and it doesn't return anything until you hit enter. So it can't be used to, say, respond to a keypress.

I tried to create such an app once using curses and then urwid... but it never worked quite right.

I'll keep my eye out if there's something new (in asyncio since I last tried) that will help.

dwhall commented 5 years ago

Oh, I just realized that the examples/udp_server.py is one way to do it. This example uses line input (not an event for each keypress like I was talking about above) and TimeEvents. The example requires running the server in one console and the client in another. Assuming Mac OS or Linux, netcat (nc) is the easiest way to have console line input transmitted via UDP to the server. I don't know of a good client for windows; though a basic telnet should do.

MiMiMeowMeow commented 5 years ago

Ahh.. yes, that should work! Thanks for your help!