SimpleXMLRPCServer and Threading

Jeff McNeil jeff at jmcneil.net
Wed Mar 28 21:09:32 EDT 2007


This is off of memory so I apologize if I don't get all of the details right.

The base SimpleXMLRPCServer uses TCPServer as it's server component
and SimpleXMLXMLRPCRequestHandler as it's handler. The handler is a
subclass of BaseHTTPRequestHandler, which itself doesn't handle any
multithreading.  You need to use one of the *MixIn classes if you want
to handle concurrent requests.

-Jeff


On 3/28/07, Erik Johnson <nobody at invalid.com> wrote:
>
> "Achim Domma" <domma at procoders.net> wrote in message
> news:460acd70$0$20282$9b4e6d93 at newsspool3.arcor-online.net...
> > Hi,
> >
> > is SimpleXMLRPCServer multithreaded or how does it handle multiple
> > clients? I want to implement a simple server which will be queried by
> > multiple processes for work to be done. The server will simply hold a
> > queue with files to process. The clients will ask for the next file.
> >
> > Do I have to sync access to the queue or is the server not threaded at
> all?
>
>
>     I don't claim to know much about the internals of the module, but it
> imports BaseHTTPServer which I am sure is multithreaded.  I did not test
> this with functions, but when you register an object in the server,
> different clients are accessing the same object:
> (The following example is modified from that given in the module
> documentation: http://docs.python.org/lib/module-SimpleXMLRPCServer.html)
>
>
> $ cat server.py
> #!/usr/bin/env python
>
> from SimpleXMLRPCServer import SimpleXMLRPCServer
>
> # Create server
> server = SimpleXMLRPCServer(("localhost", 8000))
> server.register_introspection_functions()
>
> # Register pow() function; this will use the value of
> # pow.__name__ as the name, which is just 'pow'.
> server.register_function(pow)
>
> # Register a function under a different name
> def adder_function(x,y):
>     return x + y
> server.register_function(adder_function, 'add')
>
>
> # Register an instance; all the methods of the instance are
> # published as XML-RPC methods (in this case, just 'div').
> class MyObj:
>     SEQ = None
>
>     def __init__(self):
>         self.SEQ = range(10000)
>         self.index = 0
>
>     def next_seq(self):
>         n = self.SEQ[self.index]
>         self.index += 1
>         return n
>
> server.register_instance(MyObj())
>
> # Run the server's main loop
> server.serve_forever()
>
>
> # First client calls:
> >>> import xmlrpclib
> >>> url = 'http://localhost:8000'
> >>> s = xmlrpclib.Server(url)
> >>> s.next_seq()
> 0
> >>> s.next_seq()
> 1
> >>> s.next_seq()
> 2
>
>
> # second client calls
> >>> import xmlrpclib
> >>> url = 'http://localhost:8000'
> >>> s = xmlrpclib.Server(url)
> >>> s.next_seq()
> 3
>
>
>     I did not programmatically drive these calls at the same time to try to
> force simultaneous access from separate requests, but my intuition is that
> it's a pretty good bet that SimpleXMLRPCServer has taken care of re-entrant
> issues.  It may be instructive for you to run that test yourself and
> explicitly verify requests do not interact.
>
>     Alternatively, if you really want to know for sure... Python is an
> open-source project. You can dig around in SimpleXMLRPCServer.py yourself
> and figure out exactly what it is doing:
>
> >>> import SimpleXMLRPCServer
> >>> SimpleXMLRPCServer
> <module 'SimpleXMLRPCServer' from
> '/usr/lib/python2.4/SimpleXMLRPCServer.pyc'>
> >>>
>
> ej at myBox ~
> $ vi /usr/lib/python2.4/SimpleXMLRPCServer.py
>
>
>
> see also:
> http://docs.python.org/lib/module-BaseHTTPServer.html
> http://docs.python.org/lib/module-SocketServer.html
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list