Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xml-rpc

5 views
Skip to first unread message

ahmet erdinc yilmaz

unread,
Mar 14, 2010, 4:14:49 AM3/14/10
to pytho...@python.org
Hello,

Recenetly we are developing a senior project and decide to use xmlrpclib.
However I have some questions. In the documentation I could not find any
clue about
handling requests? Does the server handles each request in a separate
thread? Or is
there some queuing mechanism for client calls? Thanks in advance.


--erdinc

Martin P. Hellwig

unread,
Mar 14, 2010, 6:17:54 AM3/14/10
to

How I usually tackle stuff like this:
[martin@aspire8930 /usr/home/martin]$ python
Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16)
[GCC 4.2.1 20070719 [FreeBSD]] on freebsd8
Type "help", "copyright", "credits" or "license" for more information.
>>> import SimpleXMLRPCServer
>>> help(SimpleXMLRPCServer)
<read it and somewhere at CLASSES it says>
CLASSES

BaseHTTPServer.BaseHTTPRequestHandler(SocketServer.StreamRequestHandler)
SimpleXMLRPCRequestHandler
SimpleXMLRPCDispatcher
CGIXMLRPCRequestHandler
SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher)
SocketServer.TCPServer(SocketServer.BaseServer)
SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher)

Aah so it is based on SocketServer, lets have a look at that:

>>> import SocketServer
>>> help(SocketServer)
Help on module SocketServer:
<reading it and then it says>

There are five classes in an inheritance diagram, four of which
represent
synchronous servers of four types:

+------------+
| BaseServer |
+------------+
|
v
+-----------+ +------------------+
| TCPServer |------->| UnixStreamServer |
+-----------+ +------------------+
|
v
+-----------+ +--------------------+
| UDPServer |------->| UnixDatagramServer |
+-----------+ +--------------------+

So the base of all these servers is BaseServer, hmm somebody must have a
laugh right now :-)

Okay lets have a look at that then:

>>> import BaseServer
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named BaseServer

Hmmm okay, lets have a look at the SocketServer source itself then, but
where is it?
>>> SocketServer.__file__
'/usr/local/lib/python2.6/SocketServer.pyc'

I bet that the non compiled file is in the same directory, let's have a
look at it with less.

>>> quit()
[martin@aspire8930 /usr/home/martin]$ less
/usr/local/lib/python2.6/SocketServer.py

And there it says among other interesting stuff:

# The distinction between handling, getting, processing and
# finishing a request is fairly arbitrary. Remember:
#
# - handle_request() is the top-level call. It calls
# select, get_request(), verify_request() and process_request()
# - get_request() is different for stream or datagram sockets
# - process_request() is the place that may fork a new process
# or create a new thread to finish the request
# - finish_request() instantiates the request handler class;
# this constructor will handle the request all by itself

def handle_request(self):
"""Handle one request, possibly blocking.

Respects self.timeout.
"""
# Support people who used socket.settimeout() to escape
# handle_request before self.timeout was available.
timeout = self.socket.gettimeout()
if timeout is None:
timeout = self.timeout
elif self.timeout is not None:
timeout = min(timeout, self.timeout)
fd_sets = select.select([self], [], [], timeout)
if not fd_sets[0]:
self.handle_timeout()
return
self._handle_request_noblock()

def _handle_request_noblock(self):
"""Handle one request, without blocking.

I assume that select.select has returned that the socket is
readable before this function was called, so there should be
no risk of blocking in get_request().
"""
try:
request, client_address = self.get_request()
except socket.error:
return
if self.verify_request(request, client_address):
try:
self.process_request(request, client_address)
except:
self.handle_error(request, client_address)
self.close_request(request)


I leave the remaining parts of your question as an exercise :-)

--
mph

hackingKK

unread,
Mar 14, 2010, 6:32:30 AM3/14/10
to Martin P. Hellwig, pytho...@python.org
Instead of using the library directly,
isn't python-twisted a better choice?

happy hacking.
Krishnakant.

Martin P. Hellwig

unread,
Mar 14, 2010, 6:50:21 AM3/14/10
to
On 03/14/10 10:32, hackingKK wrote:
> Instead of using the library directly,
> isn't python-twisted a better choice?
<cut>
Why?

--
mph

Gabriel Genellina

unread,
Mar 16, 2010, 3:04:44 AM3/16/10
to pytho...@python.org
En Sun, 14 Mar 2010 05:14:49 -0300, ahmet erdinc yilmaz
<ahmete...@gmail.com> escribió:

> Recenetly we are developing a senior project and decide to use xmlrpclib.
> However I have some questions. In the documentation I could not find any
> clue about
> handling requests? Does the server handles each request in a separate
> thread? Or is
> there some queuing mechanism for client calls? Thanks in advance.

xmlrpclib is a *client* library.
Python also provides an XMLRPC *server* in the SimpleXMLRPCServer module.
It inherits from SocketServer.TCPServer. The default behavior is to
process one request at a time, in a single process. You may alter such
behavior by additionally inheriting from ForkingMixIn or ThreadingMixIn.

--
Gabriel Genellina

Brian Quinlan

unread,
Mar 29, 2010, 9:23:12 PM3/29/10
to ahmet erdinc yilmaz, pytho...@python.org

On Mar 14, 2010, at 12:14 AM, ahmet erdinc yilmaz wrote:

> Hello,
>


> Recenetly we are developing a senior project and decide to use
> xmlrpclib.
> However I have some questions. In the documentation I could not find
> any clue about
> handling requests? Does the server handles each request in a
> separate thread? Or is
> there some queuing mechanism for client calls? Thanks in advance.

By default calls are processed serially. Look for ThreadingMixIn in:
http://docs.python.org/library/socketserver.html

And maybe read this too:
http://code.activestate.com/recipes/81549-a-simple-xml-rpc-server/

Cheers,
Brian

>
>
> --erdinc
> --
> http://mail.python.org/mailman/listinfo/python-list

0 new messages