Get tomorrow morning time, make delta from now and wait x seconds.
1 2 3 4 5 6 7 | def waitToTomorrow():
"""Wait to tommorow 00:00 am"""
tomorrow = datetime.datetime.replace(datetime.datetime.now() + datetime.timedelta(days=1),
hour=0, minute=0, second=0)
delta = tomorrow - datetime.datetime.now()
time.sleep(delta.seconds)
|
I've remembered a joke about some xxx programming style:
Q:
A:
heh. then kill -9?
how about a Timer with a timeout. or
how about something like.. (say its a threading.Thread subclass):
while self._continue_execution(): try: self._condition.acquire() self._condition.wait(self._get_seconds_till_tomorrow()) # you should check again if self._continue_execution(): . . .
Sorry.. didn't indent, bleg.
so some close() method could set a stop flag and notify _condition
Your code will be off by the current number of minutes. It probably should have been:
i.e. you left out the minutes.
For simplicity, I suggest using the time module only:
Thanks Wolfgang, you are right. I've repaired it.