473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

SimpleXMLRPCServer and Threading

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?

regards,
Achim
Mar 28 '07 #1
3 7206

"Achim Domma" <do***@procoders.netwrote in message
news:46***********************@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-Si...RPCServer.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@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


Mar 28 '07 #2
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 <no****@invalid.comwrote:
>
"Achim Domma" <do***@procoders.netwrote in message
news:46***********************@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-Si...RPCServer.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@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
Mar 29 '07 #3
Jeff McNeil wrote:
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.
Does it mean that, if I subclass from ThreadingMixIn then my exported
functions will be called from different threads? I created many multi
threaded servers, based on TCPServer, but I'm not sure about
XMLRPCServer. I used to create my own handler class and in that case, a
new handler instance was created for each request, then a new thread was
created and handle_request was called from that new thread. I guess that
in this case, a new SimpleXMLXMLRPCRequestHandler is created for each
request and a new thread is started.... but I'm not sure. Please help us
out.

By the way, we should have __server__ examples in the documentation of
xmlrpclib, right? What is the right way of contributing an example?

Best,

Laszlo

Mar 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marco Aschwanden | last post by:
I would like to develop a server based on python's xmlrpc. But I realized that SimpleXMLRPCServer does not spawn a thread for each request. How could the SimpleXMLRPCServer be turned into a...
0
by: danu kusmana | last post by:
Hi Im trying to figure out why the same server script I use is running slower in Windows than in Linux. ServerTest.py: #! /usr/bin/env python import SocketServer
9
by: Yannick Turgeon | last post by:
I plan to use XML-RPC to communicate between my python server and VB client. I just called a simple registered function (lambda x,y: x+y) and it worked. But I'm new to XML-RPC and I'm now wondering...
4
by: codecraig | last post by:
Hi, I thought I posted this, but its been about 10min and hasnt shown up on the group. Basically I created a SimpleXMLRPCServer and when one of its methods gets called and it returns a response...
0
by: Thomas G. Apostolou | last post by:
Hello all, I use Python 2.3.3 and try to patch SimpleXMLRPCServer.py with the patch i got from Python.org. so after changing to the directory where both SimpleXMLRPCServer.py and...
0
by: JDF | last post by:
I am trying to create a Windows service using SimpleXMLRPCServer and win32serviceutil. The service itself seems to be working properly (starts, stops, etc) and I can connect using an XMLRPC client...
0
by: Juju | last post by:
Hi, First, sorry for my poor English ! I used the SimpleXMLRPCServer facility of Python to develop a multithread-server, here's part of my code : -- class...
2
by: Vyacheslav Maslov | last post by:
Hi, all! I need multi threaded version of SimpleXMLRPCServer. Does python library already have implementation of this one? Or i need to implement multi threading by myself? Which way is the...
9
by: Bret | last post by:
I'm coming back to Python after an absence and it's surprising how many things I've forgotten since wandering (against my will) into Java land. Anyway, I have a need for a way to make...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.