在Pyramid关闭时运行代码
Pyramid框架支持一个叫做ApplicationCreated
的事件。不过我找不到ApplicationDestroyed
或ApplicationShutdown
这样的事件。有没有办法在程序关闭时执行某个函数呢?
除了往上找其他解决方案,我还有其他选择吗?比如,我在uWSGI里面使用gevent。也许可以让gevent或者uWSGI来运行我的关闭代码,但这样做看起来就没那么简单了。
1 个回答
2
Pyramid框架并不支持任何关闭事件。
不过,Python有一个叫做atexit
的事件,它会在解释器关闭时运行。
http://docs.python.org/library/atexit.html
import atexit
@atexit.register
def goodbye():
print "You are now leaving the Python sector."