[Medusa-dev] async question

Donovan Baarda abo at minkirri.apana.org.au
Fri May 8 14:50:48 CEST 2009


On Fri, 2009-05-08 at 08:24 -0400, Tim Smith wrote:
> medusa, and asyncore in general all operates in a single thread of
> execution.
> 
> This does not fit super well with XMLRPC servers that have long running
> functions exposed, as a long running function will block other requests.
> 
> It can be possible to have multiple threads, each running an asyncore
> loop, then the "server" would have to dispatch an incoming socket to a
> random asyncore loop to finish the execution.  This would then allow
> multiple clients to execute long running functions at the same time,
> however if you need a separate thread for every possible client, this
> defeats the purpose of medusa and you might as well use a threaded
> XMLRPC server
> 
> In general, i would only advise using medusa for XMLRPC if you are also
> using it for HTTP or other highly asynchronous transport protocols (in
> order to add an XMLRPC interface to your server, however the XMLRPC
> functions will now have the potential to block other requests)
> 
> If you are only offering XMLRPC, best go with a threaded server to
> reduce blocking when long running functions are executed.

Actually... I'm not convinced of this. Threading has it's own problems,
and async servers can do xmlrpc as well or better than threaded servers,
provided you do it right.

medusa is kind of old now, and twisted is a much better developed async
framework that has decent support for things like deferred's that allow
you to run slow stuff on the side without blocking the main async
handler. Medusa was awesome in it's time, and is still widely used for
serious stuff, but it did inspire things like twisted that are now much
better options for new projects.

>  -- Tim
> 
> 
> 
> lluis gomez i bigorda wrote:
> > hello all,
> >
> > i'm justr trying to setup a simple server using medusa but I think I'm
> > doing something wrong cause it's not async at all ::
> >
> > my script is something like this ::
> >
> >
> >
> > from socket import gethostname
> > from medusa.xmlrpc_handler import xmlrpc_handler
> > from medusa.http_server import http_server
> > import asyncore
> >
> > class xmlrpc_server(xmlrpc_handler):
> >     # initialize and run the server
> >     def __init__(self, host=None, port=8182):
> >         if host is None:
> >             host = gethostname( )
> >         hs = http_server(host, port)
> >         hs.install_handler(self)
> >         asyncore.loop( )
> >     # an example of a method to be exposed via the XML-RPC protocol
> >     def add(self, op1, op2):
> >         return op1 + op2
> >     # an infinite loop
> >     def fuck(self, op1, op2):
> >         while (op1>2):
> >                 op1 = op2
> >         return False
> >
> >     # the infrastructure ("plumbing") to expose methods
> >     def call(self, method, params):
> >         print "calling method: %s, params: %s" % (method, params)
> >         if method == 'add':
> >             return self.add(*params)
> >         if method == 'fuck':
> >             return self.fuck(*params)
> >         return "method not found: %s" % method
> > if __name__ == '__main__':
> >     server = xmlrpc_server( )
> >
> >
> >
> > ok ... the server works but if one client call the procedure "fuck"
> > the server will not attend any other petiotions  ...
> >
> > can anybody explain what i'm missing please?
> >
> > thank you very much in advance,
> >
> > ll.
> > _______________________________________________
> > Medusa-dev mailing list
> > Medusa-dev at python.org
> > http://mail.python.org/mailman/listinfo/medusa-dev
> >
> 
> _______________________________________________
> Medusa-dev mailing list
> Medusa-dev at python.org
> http://mail.python.org/mailman/listinfo/medusa-dev
-- 
Donovan Baarda <abo at minkirri.apana.org.au>
http://minkirri.apana.org.au/~abo/



More information about the Medusa-dev mailing list