Leaving an APScheduler in a while True loop I want to run a background job on my web server to do some database maintenance. I am looking at using APScheduler to do this.

I am planning on running the below code in a separate process to my main web server. I don't really want to tie the code to my web server.

Question: Is using While True pass at the end of a cron-like scheduler considered bad practice? How should it be done? (time.sleep()?)

from apscheduler.scheduler import Scheduler

@sched.interval_schedule(days=1)
def tick():
    # do a clean up job


while True:
    pass
while True: pass will consume 100 % of one CPU which is not something you want. I'm not familiar with APScheduler, but a quick look into the docs reveals a daemonic option:


  Controls whether the scheduler thread is daemonic or not.
  
  If set to False, then the scheduler must be shut down explicitly when
  the program is about to finish, or it will prevent the program from
  terminating.
  
  If set to True, the scheduler will automatically terminate with the
  application, but may cause an exception to be raised on exit.