Python Forum

Full Version: How to exit infinite While Loop?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
On a Windows PC I'm working on some code to do a task every 'n' minutes.

Normally the program will run constantly unless the system user/admin wishes to stop it.

The plans were to use a while loop to do the job and sleep to create the 'n' minute delay between each time the task gets done.

But, once the system goes into an 'infinite' while loop... what is the proper way for the user/admin to end the program (while loop) whenever they so decide?

Thanks for any help.
You could try a 'KeyboardInterrupt' exception, say "Control + C to exit"
You could also just have it happen one time, and not have a while loop at all, then use the OS' scheduler to run it every N minutes.
You could use another script to open a port. So the first script will check it and if it's open will stop the execution of the loop. You don't even need to set a value to check for or some kind of RPC