Tack on session support to a 'stateless' xml-rpc app
I have to create a python (twisted) application that accepts connections from clien开发者_如何学运维ts via XML-RPC and performs operations that might require multiple steps. The xml-rpc implementation does not have typical session support, so I need to implement it.
What I think I need is a some type of persistent object that tracks the progress of the multi-step operations, and gives the client a key that it can use to identify the operation that it initiated, to get status updates or send commands (pause/cancel etc).
To me, an appropriate model for this is "Job"; googling for "python job library" yields expected useless results.
Before I implement this, is there something existing that I can use instead?
Thanks!
I think you can have a persistent object in the server, something like :
from twisted.web import xmlrpc, server
class MultiStep(xmlrpc.XMLRPC):
def __init__(self) :
xmlrpc.XMLRPC.__init__(self)
self.db = {}
def getX(self, user, x):
self.db[user] = {'x' : x}
return 'OK'
def getY(self, user, y):
self.db[user]['y'] = y
return 'OK'
def plus(self,user) :
return self.db[user]['x'] + self.db[user]['y']
if __name__ == '__main__':
from twisted.internet import reactor
r = MultiStep()
reactor.listenTCP(6666, server.Site(r))
reactor.run()
精彩评论