Non-blocking raw_input with line editing using gevent

I am trying to implement an interactive shell on top of the internal API that gevent uses. I want the background greens to continue to work while waiting for user input, and I also want to use the readline command line functions (history, line editing, etc.).

My problem is that raw_input is blocked. There are solutions around which to replace raw_input with things like:

def raw_input(prompt): sys.stdout.write(prompt) sys.stdout.flush() select.select([sys.stdin], [], []) return sys.stdin.readline().rstrip('\n') 

This solves the lock problem; green backgrounds now work fine. But I'm losing interactive line editing features.

Any suggestions or workarounds?

+4
source share
1 answer

You can try using raw_input in the seprecate stream and then return the result to a global variable. Not sure if this will work for you, it worked for me, but in a completely different scenario

+2
source

Source: https://habr.com/ru/post/1489550/


All Articles