There is no app.stop()
if that is what you are looking for, however using module atexit
you can do something similar:
https://docs.python.org/2/library/atexit.html
Consider this:
import atexit
#defining function to run on shutdown
def close_running_threads():
for thread in the_threads:
thread.join()
print "Threads complete, ready to finish"
#Register the function to be called on exit
atexit.register(close_running_threads)
#start your process
app.run()
Also of note-atexit
will not be called if you force your server down using Ctrl-C.
For that there is another module- signal
.
https://docs.python.org/2/library/signal.html