1

I have a python script I wanted to rerun overnight on the company computer, so I made sure to turn off sleep for the computer and then started the script which had these lines

while True:
        try:
            ### Large Script
        except Exception as e:
            print(e)
            pass
        print(datetime.datetime.now(), "Done")
        time.sleep(1800)
        print(datetime.datetime.now(), "30 Minutes passed")
        time.sleep(1800)
        print(datetime.datetime.now(), "1 Hour passed")
        time.sleep(1800)
        print(datetime.datetime.now(), "1.5 Hour passed")
        time.sleep(1800)
        print(datetime.datetime.now(), "2 Hours passed, Rerunning") 

what happened is it didn't run because the period is delayed and i found the output something like this

2022-06-21 18:02:00 Done
2022-06-22 03:22:00 30 Minutes passed
2022-06-22 07:50:00 1 Hour passed
2022-06-22 10:03:00 1.5 Hour passed

while windows is telling me it didn't sleep all night, so what's going on?

enter image description here

Update: these answers don't answer my question since they're giving solutions if the time.sleep() sleeps less than what you requested, my situation is it sleeps for hours when I wanted it to sleep for 30 minutes

A.Rahman Mahmoud
  • 328
  • 1
  • 3
  • 17
  • 1
    Instead of printing every 30 minutes, try printing each 10 seconds or something so you get a better idea of what's going on. – Peter Jun 22 '22 at 10:00
  • It's suspicious that the seconds were always zero and that there were no microseconds shown at all. Looks like that output isn't really from that code. – Kelly Bundy Jun 22 '22 at 10:03
  • It's not from the code i manually did it similar to what it was @KellyBundy – A.Rahman Mahmoud Jun 22 '22 at 10:57

0 Answers0