Python uses time.sleep () to do timing tasks, but a period of time is skipped

problem description

use time for scheduled tasks, but it will always be skipped for a while. Here is the log I set to print every 5 minutes.

clipboard.png

the environmental background of the problems and what methods you have tried

it was originally thought that each sleep takes a long time (originally set to sleep 58 to 60), and then changed to the above sleep (1), there is still the above problem.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

    interval = 58 * 60
    count = interval
    while 1:
        count -= 1
        if count > 0:
            if count % 300 == 0:
                NORMAL_LOG(time.strftime(u"%Y-%m-%d %H:%M:%S", time.localtime(time.time())))
            -sharp NORMAL_LOG("c:%d" % count)
            time.sleep(1)
        else:
            try:
                thread.start_new_thread(check_code_style, ())
            except Exception:
                tip_str = u""
                NORMAL_LOG(tip_str)
                send_email_to_myself(tip_str)
            count = interval

what result do you expect? What is the error message actually seen?

the ideal state should not have skipped such a long time, did not report any errors, and found nothing after reading the relevant documents.

Sep.23,2021

time.sleep is not used for precise timing
original:
the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system.
due to the arrangement of other activities in the system, the pause time may be longer than any number of requests.
reference python.org/3/library/time.html-sharptime.sleep" rel=" nofollow noreferrer "> https://docs.python.org/3/lib.
suggests using the schedule module


obvious logic problems. When count is 0, the interval time must be twice the interval time you set-the set time.sleep time.
secondly, The interval between the first execution after the count is reset depends on the count value and the remainder of the num in count% (num).


the cause of the problem later I inadvertently discovered. It's because there's something wrong with the energy-saving configuration of my computer. You can't post pictures here, so I'll talk about it. It is that I have configured the option "put the hard drive to sleep if possible" in energy saving, and when I remove this option, the test will be normal. I don't know why this option has such an effect. If you are in sleep mode, you shouldn't start it again in the wee hours of the morning.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e52be8-43f10.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e52be8-43f10.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?