Reputation: 769
I have a program with two threaded processes that run on a loop. The problem is, I'm new enough to python that outside of closing the terminal window, I don't know the best method to properly terminate the application.
Upvotes: 1
Views: 98
Reputation: 1715
The best way to terminate any threaded application, including python, is a technique known as "cooperative shutdown". With this technique, in each thread you check if the application has been instructed to shutdown on each loop iteration, and if so, exit the loop and finish running each thread. Your shutdown condition is completely up to you but common options include catching a KeyboardInterrupt exception and then setting a shared shutdown variable, timeout, etc, etc...
Upvotes: 1