From lluisgomez at hangar.org Fri May 8 01:27:02 2009 From: lluisgomez at hangar.org (lluis gomez i bigorda) Date: Fri, 08 May 2009 01:27:02 +0200 Subject: [Medusa-dev] async question Message-ID: <4A036E46.7040807@hangar.org> 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. From groklinux at yahoo.com Fri May 8 14:24:21 2009 From: groklinux at yahoo.com (Tim Smith) Date: Fri, 08 May 2009 08:24:21 -0400 Subject: [Medusa-dev] async question In-Reply-To: <4A036E46.7040807@hangar.org> References: <4A036E46.7040807@hangar.org> Message-ID: <4A042475.1000407@yahoo.com> 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. -- 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 > From abo at minkirri.apana.org.au Fri May 8 14:50:48 2009 From: abo at minkirri.apana.org.au (Donovan Baarda) Date: Fri, 08 May 2009 13:50:48 +0100 Subject: [Medusa-dev] async question In-Reply-To: <4A042475.1000407@yahoo.com> References: <4A036E46.7040807@hangar.org> <4A042475.1000407@yahoo.com> Message-ID: <1241787048.32721.44.camel@warna.dub.corp.google.com> 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 http://minkirri.apana.org.au/~abo/