python - 在 Pyramid 关闭时运行代码

标签 python pyramid

Pyramid 支持 ApplicationCreated 事件。但是我找不到任何 ApplicationDestroyed/ApplicationShutdown 事件。是否有可能在关闭时执行某个功能。

除了进一步提升我的堆栈之外,我还有其他选择吗:即。我在uWSGI 中使用gevent。也许可以让 gevent 或 uWSGI 来运行我的关闭代码,但它肯定不是那么漂亮。

最佳答案

Pyramid 不支持任何关闭事件。

然而,Python 有一个 atexit 事件,该事件在解释器关闭时运行

http://docs.python.org/library/atexit.html

import atexit

@atexit.register
def goodbye():
    print "You are now leaving the Python sector."

关于python - 在 Pyramid 关闭时运行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7484366/

相关文章:

php - 我是一名转换为 python 的 php 程序员。请解释单元测试的重要性(或不重要)。我从来没有用 php 进行过单元测试!

python - 何时在 Pyramid 中使用route_url或route_path?

python - SQLAlchemy 找不到类名

python - 如何与 Pyramid 中的所有模板共享选定数量的数据?

python - App Engine 分片计数器和高复制数据存储

c++ - 是否有可以解析 C++ 的优秀 Python 库?

python - 在pygame python3中创建登录系统

python - 如何复制这个维基百科情节?

python - 如何在 Pyramid 中使用pyramid_celery?

python - 将 2 个 .csv 文件与 Python 进行比较,然后输出结果