您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python Flask关闭事件处理程序

Python Flask关闭事件处理程序

如果你要查找的是没有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

Python 2022/1/1 18:24:52 有222人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶