farc icon indicating copy to clipboard operation
farc copied to clipboard

Interactive Example with Asynchronous console input

Open MiMiMeowMeow opened this issue 5 years ago • 3 comments

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!

MiMiMeowMeow avatar Aug 23 '19 00:08 MiMiMeowMeow

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 avatar Aug 23 '19 02:08 dwhall

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.

dwhall avatar Aug 24 '19 03:08 dwhall

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

MiMiMeowMeow avatar Aug 25 '19 23:08 MiMiMeowMeow