[Twisted-Python] callLater

Hi. I need to implement a function for scheduling function calls at specific times. A simple implementation is: def callAt(when): from twisted.internet import reactor delta = when - datetime.now() delay = delta.days * 24 * 3600 + delta.seconds + delta.microseconds / 1000000. return reactor.callLater(delay) However I'm going to have lots of this scheduled calls, many of these are far away in the future. Can this be a problem? An alternative implementation is to use LoopingCall that, say, every 15 minutes, check the scheduled functions. Here I can think of some optimization, to avoid a linear search. Thanks Manlio Perillo

On Mon, 04 Sep 2006 18:02:51 +0200, Manlio Perillo <manlio_perillo@libero.it> wrote:
Hi.
I need to implement a function for scheduling function calls at specific times.
A simple implementation is:
def callAt(when): from twisted.internet import reactor
delta = when - datetime.now() delay = delta.days * 24 * 3600 + delta.seconds + delta.microseconds / 1000000.
return reactor.callLater(delay)
However I'm going to have lots of this scheduled calls, many of these are far away in the future.
Can this be a problem?
Profile your application and find out. Anything else you do is premature optimization and a waste of time. Jean-Paul

First of all, the subject should have been "callAt" and not callLater, sorry. Jean-Paul Calderone ha scritto:
On Mon, 04 Sep 2006 18:02:51 +0200, Manlio Perillo <manlio_perillo@libero.it> wrote:
Hi.
I need to implement a function for scheduling function calls at specific times.
A simple implementation is:
def callAt(when): from twisted.internet import reactor
delta = when - datetime.now() delay = delta.days * 24 * 3600 + delta.seconds + delta.microseconds / 1000000.
return reactor.callLater(delay)
However I'm going to have lots of this scheduled calls, many of these are far away in the future.
Can this be a problem?
Profile your application and find out. Anything else you do is premature optimization and a waste of time.
I don't think this is a premature optimization. I'm just considering two different implementations. I whould like to know if someone is using thousands instances of DelayedCall without having problems. However only now I'm noting that the reactor uses the heapq module, so there should be no performance problems. Thanks and regards Manlio Perillo

Quoting Manlio Perillo <manlio_perillo@libero.it>:
Hi.
Hi,
I need to implement a function for scheduling function calls at specific times.
[snip]
However I'm going to have lots of this scheduled calls, many of these are far away in the future.
Can this be a problem?
The real problem of this kind of solution is the lost of data if you restart your application. If your 'far away in the future' is 6 months, I won't expect my server to run 6 months (not for reliability reason, but a change of configuration for example, or a new feature of my app). So you have to store the scheduled calls somewhere. For the use of callLater, like Jean-Paul said you should try and see if it works for you. If you already store your calls somewhere it won't be hard to make a simple scheduler with a tick function. -- Thomas ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.

Thomas HERVE ha scritto:
Quoting Manlio Perillo <manlio_perillo@libero.it>:
Hi.
Hi,
I need to implement a function for scheduling function calls at specific times.
[snip]
However I'm going to have lots of this scheduled calls, many of these are far away in the future.
Can this be a problem?
The real problem of this kind of solution is the lost of data if you restart your application. If your 'far away in the future' is 6 months, I won't expect my server to run 6 months (not for reliability reason, but a change of configuration for example, or a new feature of my app). So you have to store the scheduled calls somewhere.
I'm implementing a simple calendar (using IETF icalendar as a reference). What I need to schedule are the alarms. Alarm data is stored in a relational database. So, every time the server starts, it can read alarm data from the database and do the scheduling job.
For the use of callLater, like Jean-Paul said you should try and see if it works for you. If you already store your calls somewhere it won't be hard to make a simple scheduler with a tick function.
Ok. For now I'm going to use callLater. Thanks and regards Manlio Perillo
participants (3)
-
Jean-Paul Calderone
-
Manlio Perillo
-
Thomas HERVE