Today's goal is to create a cron job type function for your favorite programming language (or reimplement one). The function should be able to take in an integer (seconds) and run a function every N seconds. For bonus provide a way to run the function every N Minutes, Hours, or Days.
Comments:
Johnathan - 10 years, 4 months ago
reply permalink
Johnathan - 10 years, 4 months ago
Oops...forgot to do hours and days. Oh well, I made my submission. Guess I lose out on bonus.
reply permalink
David - 10 years, 4 months ago
Why not use time.sleep() ? Your while loop is actively counting instead of suspending the execution thread.
reply permalink
Johnathan - 10 years, 4 months ago
I guess I misunderstood the concept.
reply permalink
David - 10 years, 4 months ago
S'all good. This website is (potentially) a great place to learn this kind of stuff, so long as other commenters actually say something. Lots of this code will end up being quick and dirty, but that can be a good way to catch some of one's ingrained habits.
reply permalink
Johnathan - 10 years, 4 months ago
100% honest I love feedback. If you want to take the time to read over my stuff and give suggestions I would really like it.
Don't want you to think I'm taking it the wrong way. I know some things, but in the big picture I'm still fairly new.
reply permalink
David - 10 years, 4 months ago
I added a randomized exit condition so it does not require a forced quit.
reply permalink
Nick Krichevsky - 10 years, 4 months ago
I decided to do it two ways because I am not sure which would be better from a system standpooint.
Solution 1, time.sleep()
Solution 2, Custom timer
reply permalink