title: Make sure only one worker launches the apscheduler event in a pyramid web app running multiple workers
body: <p>We have a web app made with pyramid and served through gunicorn+nginx. It works with 8 worker threads/processes</p>
  <p>We needed to jobs, we have chosen apscheduler. here is how we launch it</p>
  <pre><code>from apscheduler.events import EVENT_JOB_EXECUTED, EVENT_JOB_ERROR
  from apscheduler.scheduler import Scheduler
  
  rerun_monitor = Scheduler()
  rerun_monitor.start()
  rerun_monitor.add_interval_job(job_to_be_run,\
              seconds=JOB_INTERVAL)
  </code></pre>
  <p>The issue is that all the worker processes of gunicorn pick the scheduler up. We tried implementing a file lock but it does not seem like a good enough solution. What would be the best way to make sure at any given time only one of the worker process picks the scheduled event up and no other thread picks it up till next <code>JOB_INTERVAL</code>?</p>
  <p>The solution needs to work even with mod_wsgi in case we decide to switch to apache2+modwsgi later. It needs to work with single process development server which is waitress.</p>
  <h3>Update from the bounty sponsor</h3>
  <p>I'm facing the same issue described by the OP, just with a Django app. I'm mostly sure adding this detail won't change much if the original question. For this reason, and to gain a bit more of visibility, I also tagged this question with <code>django</code>.</p>