Actually, I suppose you are looking for a code that runs a loop until a key is pressed from the keyboard. Of course, the program shouldn't wait for the user all the time to enter it.
raw_input()
in python 2.7 or input()
in python 3.0, The program waits for the user to press a key.kbhit()
function in msvcrt
module.Actually, there is a recipe in ActiveState where they addressed this issue. Please follow this link
I think the following links would also help you to understand in much better way.
I hope this helps you to get your job done.