Updated below:
I have a script which has a function I made that calculates the time to set my script to sleep for based on a few factors, which means the script might not need to run again for a half hour or it could be a few days.
Now, I had thought that time.sleep(seconds) would set the program to sleep and then wake it up and run it again.
time.sleep(3600)
runScriptAgain()
Apparently this doesn't do what I thought it did. Of course most things never seem to do what I think, the joys of learning!
At any rate once I figured out that the script was never resuming I looked around for other ways to do this. Someone had mentioned os.exec
but from my (very limited) knowledge it looks like that is used to run something else from within the script. Then I tried the threading.Timer
function but that doesn't seem to do what I want either. Or I have no idea what I'm doing, which is even more likely. And then I've seen people mentioning threads and daemons and things that I have no idea about at all.
I was thinking maybe a for loop but that seems pretty amateurish(pot meet kettle!), and I'm not sure how well that would even work(if at all).
timeToSleep = SleepValue()
count = 0
while count < timeToSleep:
count + 1
time.sleep(1)
runscript()
So is there an easy way to set a script to stop running for a specific amount of time, run again, and then sleep until the next time? I figure there must be a pretty simple way to do this, but I really have no clue. I'm on Windows 7 using Python 3.2.3, and I've only been learning python for a few months now so anything complicated is likely to be outside my skill level.
Updated:
def something():
print('Hello!')
def sleep():
time.sleep(5)
runscript()
def runscript():
something()
sleep()
runscript()
Ok, that's how my code is currently setup. I tried it with this simple code and it seems the problem is that it just never wakes up? I'm not really sure what's going on. I thought it would call the first function, print the item, then sleep for 5 seconds, and repeat ad naseum. Maybe somebody can explain how I should be doing that.
Thanks!