Search code examples
pythonxml-rpc

Python: Best method to reload class in XMLRPC Server


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.


Solution

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