Make the standard-lib SimpleXMLRPCServer multi-threaded by using a simple mix-in construction.
| Python |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # Guyon Morée
# http://gumuz.looze.net/
import SocketServer
from SimpleXMLRPCServer import SimpleXMLRPCServer,SimpleXMLRPCRequestHandler
# Threaded mix-in
class AsyncXMLRPCServer(SocketServer.ThreadingMixIn,SimpleXMLRPCServer): pass
# Example class to be published
class TestObject:
def pow(self, x, y):
return pow(x, y)
def add(self, x, y) :
return x + y
def divide(self, x, y):
return float(x) / float(y)
# Instantiate and bind to localhost:8080
server = AsyncXMLRPCServer(('', 8080), SimpleXMLRPCRequestHandler)
# Register example object instance
server.register_instance(TestObject())
# run!
server.serve_forever()
|
Discussion
This implementation will probably have some scalability issues and it can't compete with the feature-set which for example Twisted has.
But I like the fact it's totally build out of standard library python modules and great for prototyping XML-RPC ideas.
As presented here: http://gumuz.looze.net/wordpress/index.php/archives/2004/12/13/async-xml-rpc-server/


Sign in to comment