title: APScheduler and Heroku: Execution of job skipped: Maximum number of running instances reached
body: <p>There was a similar question posted here 3 years ago:</p>
  
  <p><a href="https://stackoverflow.com/questions/20264298/warningapscheduler-schedulerexecution-of-job-skipped-maximum-number-of-runnin">WARNING:apscheduler.scheduler:Execution of job skipped: maximum number of running instances reached (1)</a></p>
  
  <p>But the question was never fully answered.</p>
  
  <p>I have processes that execute every 3 hours.  I fire off my commands to update my database, but somehow they are not closing.  So in a few weeks I get the error "Execution of job skipped: maximum number of running instances reached (1).   But at any rate, is there a way to terminate my commands so they free up and don't accumulate?</p>
  
  <p>The original post suggests a command called proc.terminate.  What library is this from? How do I implement it in python?</p>
  
  <p>For what it is worth, here is my schedule from APScheduler</p>
  
  <pre><code>@scheduler.scheduled_job('cron', hour='0,3,6,9,12,15,18')
  def clock_scheduled_commands():
      print('Updating Tables')
      updatePrices.main()
      print('Updating Margins')
      calculateMargins.main()
      #print('Pushing to Perm')
      #PushToPerm.main()
      print(time.strftime("%A, %d. %B %Y %I:%M:%S %p"))
  </code></pre>
  
  <p>Note that the updatePrices.main() and calculateMargins.main() both return 0 indicating that they are complete.  They also both close the cursor at the end (as far as I can tell).</p>
  
  <p>EDIT: Here is my Procfile for Heroku as requested:</p>
  
  <pre><code>web: gunicorn controller:app
  clock: python scripts/clock.py
  </code></pre>