在Pyramid关闭时运行代码

1 投票
1 回答
900 浏览
提问于 2025-04-17 02:40

Pyramid框架支持一个叫做ApplicationCreated的事件。不过我找不到ApplicationDestroyedApplicationShutdown这样的事件。有没有办法在程序关闭时执行某个函数呢?

除了往上找其他解决方案,我还有其他选择吗?比如,我在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."

撰写回答