dbader / schedule

Python job scheduling for humans.
https://schedule.readthedocs.io/
MIT License
11.71k stars 960 forks source link

Is there any ways to run without while True? #551

Open liudonghua123 opened 1 year ago

liudonghua123 commented 1 year ago

I like this library, it is simple and easy to use. However, the program process maybe continues to use the system resources like cpu resources.

For example, if I add a print statement after schedule.run_pending() like this. The schedule awake will be printed every second.

while True:
    schedule.run_pending()
    print("schedule awake")
    time.sleep(1)

So is there any ways to make the code to eliminate while True loop or make schedule.run_pending() block to wait for the next job. And during the idle time, no or few system resources are needed.

madmage9999 commented 1 year ago

Maybe you can try putting sleep(x) at the end of each process that needs to be completed if you know how long in-between intervals so that it wakes up before the next one needs to be run.

QZLin commented 1 year ago

See Time until the next execution