xml-rpc/twisted question

Guyon Morée gumuz at looze.net
Fri Dec 5 17:13:07 CET 2003


Hi all,

Below this message you can see my code. It is a modified version of the
twisted xml-rpc server examples. I am trying to figure out how to implement
non-blocking methods. I found out that I have to use 'defer' to do that, but
I have no clue how to do this. Unfortunately the documentation could not
make this clear to(unless I am missing some docs). I have already added a
function called xmlrpc_block to represent a actual 'blocking function'.

I hope someone can show me how to modify this so the server does not block
any other clients when xmlrpc_block is called.

thanx,
Guyon

====================================================================
#TestServer.py

from twisted.web import xmlrpc, server
from twisted.internet import reactor

class Example(xmlrpc.XMLRPC):
    """An example object to be published."""

    def xmlrpc_echo(self, x):
        """Return all passed args."""
        return x

    def xmlrpc_block(self, duration=10):
        """block the instance for a specified duration"""
        import time
        time.sleep(duration)
        return "i slept %s seconds!" % (str(duration))


# this only runs if the module was *not* imported
if __name__ == '__main__':
    r = Example()
    reactor.listenTCP(7080, server.Site(r))
    reactor.run()






More information about the Python-list mailing list