WSGI 后处理清理 [英] WSGI post-process cleanup

查看:93
本文介绍了WSGI 后处理清理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个带有 mod_wsgi 和 apache 的 TurboGears 应用程序,使用用 Ming 包裹的 pymongo 来实现持久性.为了防故障和扩展我的应用程序,我有兴趣通过 pymongo 复制集连接.

I'm running a TurboGears app with mod_wsgi and apache, using pymongo wrapped with Ming for persistence. To failproof and scale my app I was interested in using mongo's support for replica sets through a pymongo ReplicaSetConnection.

但是,正如上面链接中所指定的,在处理完每个 pymongo ReplicaSetConnection 对象时必须调用 close(),否则会留下一堆僵尸进程浮动周围(wtf pymongo).Ming 不太支持这种行为(它实际上并不真正支持副本集),但我设法编写了一个清理函数来关闭所有 pymongo 连接.

However, as specified in the above links, one must call close() when done with every pymongo ReplicaSetConnection object, otherwise it will leave a bunch of zombie processes floating around (wtf pymongo). This sort of behavior isn't supported very well in Ming (it actually doesn't really support Replica Sets yet), but I managed to write a cleanup function that closes all pymongo connections.

现在我想在所有应用程序进程的进程清理中运行我的清理功能.它们有两个基本入口点:通过 apache 和 paste 命令的 mod_wsgi.将我的清理添加到粘贴命令中没有问题,但是有没有办法为 wsgi 进程指定清理功能?

Now I want to run my cleanup function on process cleanup for all my app processes. These have two basic entry points: mod_wsgi through apache and paster commands. It is no problem to add my cleanup to the paster commands, but is there a way to specify a cleanup function for wsgi processes?

如果没有,还有其他正确设置的建议吗?

If not, any other advice for setting this up correctly?

推荐答案

您无法保证您的代码甚至会被调用,因为进程可能会在调用之前崩溃或被强行退出.有了这个警告,请阅读有关此特定问题的 mod_wsgi 文档:

You have no guarantee your code will even be called as processes can just crash or be forcibly exited before it is called. With that caveat, read the mod_wsgi documentation about this specific issue:

http://code.google.com/p/modwsgi/wiki/RegisteringCleanupCode

这篇关于WSGI 后处理清理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆