Re: [Twisted-Python] xmlrpc deferred

Discussion in 'Python' started by Jp Calderone, May 27, 2005.

  1. Jp Calderone

    Jp Calderone Guest

    On Fri, 27 May 2005 22:28:06 +0300, Catalin Constantin <> 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.

    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.

    >
    >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).

    >
    >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
     
    Jp Calderone, May 27, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Etienne Posthumus
    Replies:
    1
    Views:
    1,159
    Roger Binns
    Apr 1, 2004
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    468
    Jean-Paul Calderone
    Jun 17, 2008
  3. marco

    [TWISTED] Howto Deferred

    marco, Jul 14, 2011, in forum: Python
    Replies:
    2
    Views:
    746
    Jean-Paul Calderone
    Jul 14, 2011
  4. Glyph
    Replies:
    0
    Views:
    199
    Glyph
    Dec 27, 2012
  5. Glyph
    Replies:
    0
    Views:
    171
    Glyph
    Apr 3, 2013
Loading...

Share This Page