storing variable value
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sat Apr 11 08:00:00 EDT 2009
On Sat, 11 Apr 2009 21:36:43 +1000, Daniel Dalton wrote:
> Hi!
>
> I'm writing a program to provide me with battery warnings when my
> battery hits certain levels. It just checks the current level and does
> something. I plan to call it from a a cron job. But If the cron runs
> every minute, warnings every minute would be rather annoying. so is
> there a way to make the script check if it has already ran before? eg.
> can I write to a variable on one run of the program, and on the next
> read that value that was written?
No, every time cron calls your script, it calls it as new. If you want
persistent storage, you need to write to persistent storage like a file.
Another solution is to use a daemon which is running continuously in the
background. Because that's a long-running process, the daemon can then
decide how often it checks the battery, and how often it notifies you.
However, writing correct daemons is not something for a beginner. I
recommend you just stick to writing your persistent data to a file
somewhere, and sticking to cron.
--
Steven
More information about the Python-list
mailing list