[Twisted-Python] xmlrpc function return message to client asynchronously

Tristan Seligmann mithrandi at mithrandi.net
Thu Jan 19 12:02:50 EST 2012

On Thu, Jan 19, 2012 at 6:41 PM, Hanusz L. <Hanusz at aegtranzcom.com> wrote:
> I'd like to create a xmlrpc function get_message with the following characteristic :
>  - If the server doesn't have any message to send the client, the server will answer with a timeout after 60s (and the client can retry)
>  - If the server has a message to send to the client, the answer is sent directly
> To do that, can I do the following:
> - create a deferred in the xmlrpc function with a calllater of 60s and keep a reference to this deferred in the factory
>  * If the server has no message to send, the deferred will be called by the reactor and answer a timeout
>  * If the server has a message to send, it will call the deferred in his own code (with a parameter ?) before the reactor and answer the message.

The object returned by callLater() provides the IDelayedCall[1]
interface. If you keep a reference to this object as well as the
deferred, then you can cancel the call when you return a response by
calling the .cancel() method.

[1] http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IDelayedCall.html
mithrandi, i Ainil en-Balandor, a faer Ambar

More information about the Twisted-Python mailing list