for i in range(0, 365):
    t = datetime.datetime.today()
future = datetime.datetime(t.year, t.month, t.day, 2, 0)
if t.hour >= 2:
    future += datetime.timedelta(days=1)
time.sleep((future - t).seconds)
In Python, how can I put a thread to sleep until a specific time?