Python Forum

Full Version: Waiting for the user input while executing the program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello !

Is there a way to make a program wait for the user input while executing a the rest of the code ?  For example i have a while loop which does stuff and if a user types in "stop" the loop will stop. The problem i run into was that a program always waited for the user input and didn't execute any further until i typed something in it !
You can run two separate threads/process

https://docs.python.org/2/library/multiprocessing.html
You could put your while loop inside a try/catch, and then to stop it you'd have to hit ctrl+c.

OR, you'd need to implement one of the ways of doing more than one thing at once. Perhaps that's threading. Perhaps that's using print() and then reading stdin every time you iterate through the loop.

Threading would probably be easier, since the docs would give you pretty much everything you need. Checking stdin would be more fun, though :p
Thank you for you answers ! The threading is that thing i might have been looking for !