I have a non-blocking read from sys.stdin using select which alternates handlers for my socket and user input:
while True:
input_ready, _, _ = select.select([my_socket, sys.stdin], [], [])
for sender in input_ready:
if sender == sys.stdin:
process_user_input()
elif sender == my_socket:
process_socket_reply()
in process_user_input() I have:
command = input()
to get and handle user input.
I want to show a prompt to give a terminal-like view to my users; just like what when using input('> ') in a blocking stdin input we can achieve.
But, if I use input('> ') in my process_user_input(), > will be printed after user entered his command (as expected!)
some_command
> Invalid command.
How can I do that?
NOTE: As I have another events happening in my code, there may be some prints in stdout (thus, print('> ', end='') will fail). So I want my > to be present whenever I'm waiting for inputs, even after some prints in terminal.