Python/Jython - threading.Timer()
Ype Kingma
ykingma at accessforall.nl
Fri Dec 20 13:26:56 EST 2002
VLP wrote:
> Ype Kingma <ykingma at accessforall.nl> wrote in message
> news:<3e021ce6$0$129$e4fe514c at dreader5.news.xs4all.nl>...
>> The Timer class is new in 2.2.
>> This might do the trick:
>>
>> from threading import Thread
>> import time
>>
>> class Timer(Thread):
>> def __init__(self, interval, function, *args, **kwargs):
>> Thread.__init__()
>> self.interval = interval
>> self.function = function
>> self.args = args
>> self.kwargs = kwargs
>> self.start()
>>
>> def run(self):
>> time.sleep(self.interval)
>> return self.function(*self.args, **self.kwargs)
>>
>> I'm not sure about the args and kwargs stuff, but it works without
>> arguments.
>> You could probably just copy the Timer class from the python 2.2
>> distribution; I don't have it ready here.
>>
>> Have fun,
>> Ype
>
> Thanks a lot... this works great!
You can delete the final return, the return value is ignored anyway.
Have fun,
Ype
--
email at xs4all.nl
More information about the Python-list
mailing list