[Twisted-Python] Re: how to get the result of a callLater-scheduled func?

Stefan Rank list-ener at strank.info
Thu Mar 8 17:40:21 EST 2007


on 08.03.2007 20:37 Jean-Paul Calderone said the following:
> On Thu, 08 Mar 2007 19:39:21 +0100, Stefan Rank <list-ener at strank.info> 
> wrote:
>> Hi,
>>
>> I am scheduling a function with `callLater`.
>> The function happens to return a Deferred (but it might return anything),
>> and I was searching for an easy way to add a callback in order to
>> get the result.
<snip>
> 
> It's probably possible, but I'm not sure it's ideal.  It sounds like you
> have a use-case for the `deferLater' function which has been proposed for
> inclusion:
> 
>  http://twistedmatrix.com/trac/ticket/1875
> 
> With it, your example would look like either:
> 
>   d = deferLater(0)
>   d.addCallback(lambda ignored: test('James'))
>   d.addCallback(stopVerbose)
> 
> Or:
> 
>  d = deferLater(0, test, 'James')
>  d.addCallback(stopVerbose)
> 
> Would that save enough typing to satisfy your use case?
> 
> Jean-Paul

Thanks, that's almost what I was looking for. :)

What is lost is the access to the DelayedCall, i.e. you cannot cancel or 
reschedule anymore.

The discussion at the ticket page revolves around which of the two 
variants above is preferable.
I very much prefer the second one,
but if the callable argument would default to None, then a simple::

    if callable_ is not None:
        ... # only now use addCallback inside deferLater

would allow both versions without any overhead.
If the DelayedCall functionality could be integrated somehow than I 
think this could simply replace reactor.callLater.

I'll post at the ticket page.

thanks again,
stefan





More information about the Twisted-Python mailing list