Python Forum
How to exit infinite While Loop? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to exit infinite While Loop? (/thread-4299.html)



How to exit infinite While Loop? - Fran_3 - Aug-06-2017

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.


RE: How to exit infinite While Loop? - sparkz_alot - Aug-06-2017

You could try a 'KeyboardInterrupt' exception, say "Control + C to exit"


RE: How to exit infinite While Loop? - nilamo - Aug-10-2017

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.


RE: How to exit infinite While Loop? - wavic - Aug-10-2017

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