如果你要查找的是没有app.stop(),但是使用模块atexit
可以执行类似的操作:
https://docs.python.org/2/library/atexit.html
考虑一下:
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()
另外,atexit
如果你使用Ctrl-C
强制关闭服务器,则不会调用。
为此,还有另一个模块- signal
。