[Twisted-Python] Updated defer.html

Bob Ippolito bob at redivi.com
Mon Mar 10 21:36:30 EST 2003


On Monday, Mar 10, 2003, at 17:18 America/New_York, Glyph Lefkowitz 
wrote:

> On Monday, March 10, 2003, at 11:34 AM, Clark C. Evans wrote:
>
>> BTW, is there anyway to ask the reactor to run it's current 'queue'
>> and then _stop_ when it's idle.  in other words, I'd like
>> something like:
>>
>>    reactor.run(daemon=0)  # only runs currently queued stuff
>
> If the OS would do something sensible like give us a queue of events 
> to run, we could do that.  However, the reactor already goes through a 
> few contortions to create the illusion that something like that is 
> happening in the background; it is difficult to deterministically say 
> what the "current queue" is, especially given the surprising behavior 
> of certain modules like HTTP, which register infinitely recurring 
> timers.

Well, the simple solution is just to make a DeferredList with all of 
your "high level tasks".  When that DeferredList completes, do a 
reactor.stop().

On a somewhat related note, something that might be of some utility is 
to have some sort of "deferred callback wrapper" for callback or 
errback that allows you to make callbacks that don't expect a result or 
to integrate into the deferred callback chain.  It's something that 
happens pretty often I think?  It'd be a really simple construction:

class Passthrough:
	def __init__(self, fn):
		self.fn = fn
	def __call__(self, result, *args, **kwargs):
		self.fn(*args, **kwargs)
		return result

Is something like that worthy of sitting in defer.py ?

-bob





More information about the Twisted-Python mailing list