Python: Best method to reload class in XMLRPC Server

安稳与你 提交于 2020-02-05 04:24:06

问题


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.

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.


回答1:


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




回答2:


If reload doesn't work, you could try twisted.python.rebuild; your application need not be written in Twisted to use this twisted.python utility.

I also recently saw this livecoding thing ("a code reloading library for Python"), but it talks about a custom module system and I don't know what's going on there.



来源:https://stackoverflow.com/questions/2064935/python-best-method-to-reload-class-in-xmlrpc-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!