本文介绍了在 Pyramid 关闭时运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pyramid 支持 ApplicationCreated 事件.但是我找不到任何 ApplicationDestroyed/ApplicationShutdown 事件.是否有可能在关机时执行一个函数.

Pyramid supports an ApplicationCreated event. However I can't find any ApplicationDestroyed/ApplicationShutdown event. Is it at all possible do execute a function upon shutdown.

除了进一步提升我的筹码之外,我还有其他选择吗:即.我在 uWSGI 中使用 gevent.有可能让 gevent 或 uWSGI 来运行我的关闭代码,但它肯定没有那么漂亮.

Do I have any choice other than to go further up my stack: ie. I'm using gevent inside uWSGI. It might be possible to get gevent or uWSGI to run my shutdown code, but it certainly isn't as pretty.

推荐答案

Pyramid 不支持任何关闭事件.

Pyramid does not support any shutdown event.

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

However Python has a atexit event, that runs on interpreter shutdown

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

import atexit

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

这篇关于在 Pyramid 关闭时运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 19:23