Accepted solution: Python: How to get input from console while an infinite loop is running? from timgeb
I have been searching for an answer to this for two months on and off. I am taking on a rather large undertaking with the project I am currently working on, and eventually would like the script to output something to the terminal whilst allowing the user to enter commands.
The only solution that I have thought of thus far, is to implement curses with two 'windows', allowing keyboard interrupts via getch() to print characters to the screen in a manner that would parse each key press and print the character to the second window. I would do this in a while loop, allowing the script to function as normal while allowing the user to enter commands, simply adding the characters from each keypress to a string, and once enter is pressed resolve the entered text.
If there is a better what to do this than the amount of scripting the curses process would require that would be great! I have no idea of what the process for that should be, though (I don't even know if my curses idea would work). I have The Python Standard Library by Example, and noticed a section on multiple processes working together, is this what I should be looking into?
Sample:
def message():
print "Writing to screen during raw_input() pause."
ipt = raw_input('>>> ') #get input from user
# execute message() here even if user has not entered any information
Terminal:
"Writing to screen during raw_input() pause."
>>>
Ideally it would print output to the screen above the input line.
Thanks!