[Twisted-Python] Questions about twisted.python.delay.Delayed

Glyph Lefkowitz glyph at twistedmatrix.com
Sun Sep 30 16:34:59 MDT 2001


On Sunday, September 30, 2001, at 01:20  PM, Matt Campbell wrote:

> I'm a relatively new user of Twisted (started using it in late August
> to write a custom server), and I have a few questions about the
> twisted.python.delay.Delayed class.

Welcome to the club!

> 1.  Why does Delayed measure time in units of five-second ticks by
> default?

To highlight the fact that tick-time is not the same thing as 
real-time.  It's adjustable.

> 2.  Why is Delayed.run() called every five seconds or so even when there
> are no delayed tasks scheduled?  Wouldn't the process's CPU usage be
> slightly lower if Delayed.timeout() returned None when the queue is 
> empty?

A Delayed is a simulation, which is advancing through time at some 
multipler of real time.  I originally intended that other kinds of 
scheduled callbacks would work differently, but it so happens that 
Delayed works really fulfill that whole requirement.

Your optimization sounds like a good idea, though.

> 3.  What is the recommended way to specify, for example, that a function
> should be called approximately 30 seconds from now?  Should I pass 6 as
> the number of ticks to Delayed.later(), or is there a better way to do 
> it?

You should create your own Delayed for processing whatever type of 
events these are, and give it an appropriate ticktime.  If you have an 
event that happens every 30 seconds, make the ticktime 30, and use 
Delayed.loop with an argument of 1 to kick off your callback.

--
______      you are in a maze of twisted little applications, all
|   |_\     remarkably consistent.
|     |          -- glyph lefkowitz, glyph @ twisted matrix . com
|_____|             http://www.twistedmatrix.com/





More information about the Twisted-Python mailing list