title: How to use ApScheduler correctly in FastAPI？
body: <pre><code>from fastapi import FastAPI
  from fastapi.middleware.cors import CORSMiddleware
  import uvicorn
  import time
  from loguru import logger
  from apscheduler.schedulers.background import BackgroundScheduler
  
  app = FastAPI()
  app.add_middleware(
      CORSMiddleware,
      allow_origins=[&quot;*&quot;],
      allow_credentials=True,
      allow_methods=[&quot;*&quot;],
      allow_headers=[&quot;*&quot;],
  )
  
  test_list = [&quot;1&quot;]*10
  
  def check_list_len():
      global test_list
      while True:
          time.sleep(5)
          logger.info(f&quot;check_list_len：{len(test_list)}&quot;)
  
  @app.on_event('startup')
  def init_data():
      scheduler = BackgroundScheduler()
      scheduler.add_job(check_list_len, 'cron', second='*/5')
      scheduler.start()
  
  @app.get(&quot;/pop&quot;)
  async def list_pop():
      global test_list
      test_list.pop(1)
      logger.info(f&quot;current_list_len:{len(test_list)}&quot;)
  
  
  if __name__ == '__main__':
      uvicorn.run(app=&quot;main3:app&quot;, host=&quot;0.0.0.0&quot;, port=80, reload=False, debug=False)
  </code></pre>
  <p>Above is my code, I want to take out a list of elements through get request, and set a periodic task constantly check the number of elements in the list, but when I run, always appear the following error:</p>
  <pre><code>Execution of job &quot;check_list_len (trigger: cron[second='*/5'], next run at: 2021-11-25 09:48:50 CST)&quot; skipped: maximum number of running instances reached (1)
  2021-11-25 09:48:50.016 | INFO     | main3:check_list_len:23 - check_list_len：10
  Execution of job &quot;check_list_len (trigger: cron[second='*/5'], next run at: 2021-11-25 09:48:55 CST)&quot; skipped: maximum number of running instances reached (1)
  2021-11-25 09:48:55.018 | INFO     | main3:check_list_len:23 - check_list_len：10
  INFO:     127.0.0.1:55961 - &quot;GET /pop HTTP/1.1&quot; 200 OK
  2021-11-25 09:48:57.098 | INFO     | main3:list_pop:35 - current_list_len:9
  Execution of job &quot;check_list_len (trigger: cron[second='*/5'], next run at: 2021-11-25 09:49:00 CST)&quot; skipped: maximum number of running instances reached (1)
  2021-11-25 09:49:00.022 | INFO     | main3:check_list_len:23 - check_list_len：9
  </code></pre>
  <p>It looks like I started two scheduled tasks and only one succeeded, but I started only one task. How do I avoid this</p>