[Twisted-Python] Questions about twisted.python.delay.Delayed
![](https://secure.gravatar.com/avatar/b6b35719792852ae43a0fa78b66aa57b.jpg?s=120&d=mm&r=g)
Hello, 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. 1. Why does Delayed measure time in units of five-second ticks by default? 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? 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? Thank you. -- Matt Campbell <http://www.pobox.com/~mattcampbell/>
![](https://secure.gravatar.com/avatar/3477a9de290ec6d77129af504faa1c0b.jpg?s=120&d=mm&r=g)
On Sun, 30 Sep 2001, Matt Campbell <mattcampbell@pobox.com> wrote:
1. Why does Delayed measure time in units of five-second ticks by default?
Why does it matter? In general, I create my own, 1-second-tick, delayeds.
Depends on the tick time. main.theTimeouts's ticktime is 1. -- The Official Moshe Zadka FAQ: http://moshez.geek The Official Moshe Zadka FAQ For Dummies: http://moshez.org Read the FAQ
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Sunday, September 30, 2001, at 01:20 PM, Matt Campbell wrote:
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.
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.
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/
![](https://secure.gravatar.com/avatar/3477a9de290ec6d77129af504faa1c0b.jpg?s=120&d=mm&r=g)
On Sun, 30 Sep 2001, Matt Campbell <mattcampbell@pobox.com> wrote:
1. Why does Delayed measure time in units of five-second ticks by default?
Why does it matter? In general, I create my own, 1-second-tick, delayeds.
Depends on the tick time. main.theTimeouts's ticktime is 1. -- The Official Moshe Zadka FAQ: http://moshez.geek The Official Moshe Zadka FAQ For Dummies: http://moshez.org Read the FAQ
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Sunday, September 30, 2001, at 01:20 PM, Matt Campbell wrote:
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.
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.
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/
participants (3)
-
Glyph Lefkowitz
-
Matt Campbell
-
Moshe Zadka