xmlrpc Server
Fredrik Lundh
fredrik at pythonware.com
Mon Jun 4 10:08:45 EDT 2001
Andrew Williams wrote:
> So... How in the world do I keep a persistent object as the request
> handler? For example, what if I wanted to use xmlrpc as a front-end
> to a db; I would want the connection to the db to be persistent so I
> wouldn't incur a speed penalty for connecting/disconnecting whenever
> the request handler was called.
as its name implies, a request handler object handles a
single request.
to create a "persistent" object, attach it to the server
class. something like this could work:
class TestRequestHandler(xmlrpcserver.RequestHandler):
...
def add(...):
self.server.x = self.server.x + value
return "sum = %s" % self.server.x
class TestServer(SocketServer.TCPServer):
def __init__(self, port=8000):
self.x = 0
SocketServer.TCPServer.__init__(self, ('', port), TestRequestHandler)
server = TestServer()
server.serve_forever()
</F>
More information about the Python-list
mailing list