Make a function call itself after set amount of time

Peter Otten __peter__ at web.de
Fri Jan 16 05:13:41 EST 2004


Bart Nessux wrote:

> Peter Otten wrote:
>> Bart Nessux wrote:
>> 
>> 
>>>Bart Nessux wrote:
>>>
>>>>How do I make a function call itself every 24 hours. Also, is there a
>>>>way to start the program automatically w/o depending on the OS functions
>>>>like 'Task Scheduler' or 'Start Up Items'... this is on Windows 2k and
>>>>xp. Below is an example of what I'm trying to do.
>> 
>> 
>> [...]
>> 
>> 
>>>I figured it out. I added this to the function definition:
>>>ipconfig_email()
>> 
>> 
>> Note that Python has a limit for nesting functions:
>> 
>> 
>>>>>depth = 0
>>>>>def callself():
>> 
>> ...     global depth
>> ...     depth += 1
>> ...     callself()
>> ...
>> 
>>>>>try:
>> 
>> ...     callself()
>> ... except RuntimeError, e:
>> ...     print "depth", depth
>> ...     print e
>> ...
>> depth 999
>> maximum recursion depth exceeded
>> 
>> 
>>>>>999/365.25
>> 
>> 2.7351129363449691
>> 
>> This means that your app will probably crash in less than three years.
>> Would that be a problem on W2K ?
>> 
>> If so, a loop could go much longer:
>> 
>> while True:
>>     ipconfig_email()
>> 
>> Seriously, you should reconsider the OS features.
>> 
>> Peter
>> 
> 
> The computers are turned off and on... the script starts at boot. I
> don't think I'll hit a limit, do you?

No, I just wanted to warn you that your recipe may fail when applied on
tasks that are invoked with higher frequency - and of course test your
confidence in W2K :-)

Peter



More information about the Python-list mailing list