Events

Anand B Pillai abpillai at lycos.com
Mon Dec 16 06:36:50 EST 2002


You can use 'Timer' objects declared in the module threading
for this.

Section 7.5.7 Guido's Python Tutorial
<QUOTE>
7.5.7 Timer Objects

This class represents an action that should be run only after a
certain amount of time has passed -- a timer. Timer is a subclass of
Thread and as such also functions as an example of creating custom
threads.
</QUOTE>

def func_that_does_something_special():
    # loooooooooong calculation...

def mytimer(interval, num=1):
    
    count = 0
    while count < num: 
         count += 1
         t = Timer(interval, func_that_does_something_special)
         t.start()
          

The optional argument num can be used to perform the operation
a stipulated number of times etc...

Best Regards

Anand B Pillai

Wojtek Walczak <gminick at hacker.pl> wrote in message news:<slrnavk9bf.o8.gminick at hannibal.localdomain>...
> Dnia Fri, 13 Dec 2002 16:27:48 +0000, Tetsuo napisa³(a): 
> > Can I make Python do something, say, every midnight?
> If you really need that, you should use cron or at or sth like that.
> 
> > Or stop a
> > calculation after one second?
> % python
> [...]
> >>> import signal
> >>> print signal.alarm.__doc__
> alarm(seconds)
> 
> Arrange for SIGALRM to arrive after the given number of seconds.
> >>> 
> 
> Take a look at: <http://python.org/doc/2.2/lib/module-signal.html>.



More information about the Python-list mailing list