[Twisted-Python] xmlrpc deferred

Catalin Constantin catalin at dazoot.ro
Fri May 27 13:56:49 MDT 2005


Friday, May 27, 2005, 10:46:21 PM, Jp Calderone wrote:
> On Fri, 27 May 2005 22:28:06 +0300, Catalin Constantin <catalin at dazoot.ro> wrote:
>>Hi there,
>>
>>I have the following xmlrpc method:
>>
>>class FeederResource(xmlrpc.XMLRPC):
>>        def __init__(self):
>>                xmlrpc.XMLRPC.__init__(self)
>>                self.feeder=Feeder()
>>
>>        def xmlrpc_getList(self, id):
>>                return self.feeder.get_urls(id)
>>
>>The thing is that the self.feeder.get_urls takes too long to execute
>>and while the request is running all the others are blocked.
>>I want that while it computes the result the other XML RPC methods to
>>be available.

> The only answer here is to make get_urls() take less time.

I can't :)

> What is it doing?  Is it blocking on network I/O?  Querying a
> database?  Prompting for user input?   _It_ should be creating and
> returned a Deferred (and later calling it back with a result), most
> likely, since it is the long-running operation.

Mainly, database queries.

>>
>>I wanted to use deferrals but i found no viable example.
>>
>>Eg what i've tried to do:
>>        def xmlrpc_getList(self, id):
>>                log.debug("getList is here for id %s" % id)
>>                d = defer.Deferred()
>>                d.addCallback(self.feeder.get_urls)
>>                return d

> Deferred don't make things asynchronous, cooperative, or
> non-blocking.  They only make dealing with callbacks more
> convenient.  If you add a blocking function as the callback to a
> Deferred, it will block the reactor just as effectively as if you
> called it yourself (bacause all that happens inside the Deferred is
> that the function gets called).

Ok, i got this now.
Is there any suggested way to make the call to that method in a
separate thread and return the result after the thread is done, and meanwhile
the other XMLRPC methods not to be blocked ?

What bothers me is that while the call to getList is not done all the
other functionality of the app is on hold.



>>
>>My method feeder.get_urls is never called !
>>

> In the above code, nothing ever "fires" the Deferred - calls
> .callback() on it - so, never having a result, it never bothers to
> invoke any of its callbacks.  Deferred just hook results up to
> callbacks.

> Jp

> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

-- 
Catalin Constantin
Dazoot Software
http://www.dazoot.ro





More information about the Twisted-Python mailing list