Reputation: 41
I'm trying to implement an interactive shell over an internal API which uses gevent. I want the background greenlets to continue running while waiting on user input, and I also want readline command-line functionality (history, line editing, etc.)
My problem seems to be that raw_input is blocking. There are solutions around which 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 blocking problem; the background greenlets now run fine. But I lose the interactive line-editing functionality.
Any suggestions or workarounds?
Upvotes: 4
Views: 694
Reputation: 1315
You could try using raw_input in a seprecate thread and then returning the result to a global variable. Not sure if this would work for you, it worked for me but in an entirely different scenario
Upvotes: 2