Python:在 XMLRPC 服务器中重新加载类的最佳方法 [英] Python: Best method to reload class in XMLRPC Server

查看:26
本文介绍了Python:在 XMLRPC 服务器中重新加载类的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多线程 xmlrpc 服务正在运行,它在内存中存储了大约 2G 的大量数据.目前,如果我想更新服务器公开的方法,我必须重新启动服务.这里的问题是,如果我重新启动服务,它需要使用数据库或使用搁置数据将内存中的所有数据加载回内存.

I have a multit-threaded xmlrpc service running which stores a huge amount of data ~2G in memory. Currently, if I want to update a method the server exposes I have to restart the service. The problem here is that if I restart the service it needs to load all of the data it had in memory back into memory by using a database or using shelved data.

我正在使用这样的方法:

I am using methods like this:

xmlrpc_getUser(self, uid):
    return self.users[uid]

我希望我能做的只是使用这些方法作为另一个模块的代理,所以我的方法看起来更像这样

What I was hoping I could do is just use these methods as a proxy to another module, so my methods would look more like this

xmlrpc_getUser(self, uid):
    return self.proxy.getUser(uid)

这样我就可以在开发服务器上更新代码,然后只需将我的更新代理模块复制到生产服务器,而无需重新启动.

This way I could update code on the development server then simply copy my update proxy module to the production server without the need for a restart.

我尝试添加导入 service_proxy到我的 xmlrpc 服务控制器的构造函数,但我认为该模块已缓存并且不会重新加载.

I tried adding import service_proxy to the constructor of my xmlrpc service controller, but I think the module is cached and won't reload.

有什么好办法吗?谢谢.

Is there a good way to do this? Thanks.

推荐答案

您可以使用 重新加载 方法.您需要编写一些代码来检查模块文件的最后修改时间.

You could use the reload method. You would need to write some code to check the last modified time of the modules file.

这篇关于Python:在 XMLRPC 服务器中重新加载类的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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