title: How to exit/terminate a job earlier and handle the raised exception in apscheduler?
body: <p>I have a blocking scheduler launching 3 jobs, nothing fancy. The problem is that when I try to exit from any of the jobs earlier, using <code>exit(3)</code> for instance, it throws an exception and the whole stack. I looked for a way to catch this exception and not display the whole error/stack, but without luck. I tried adding a listener like below, but it still prints the whole stack. Which is the proper way to exit from a blockingscheduler's job ahead of it's normal termination?</p>
  
  <pre><code>def make_db_snapshot(dataset, args):
      databases = ''
  
      print_header()
  
      snapshots_no = count_snapshots(dataset)
      ....
  
  def scheduler_listener(event):
      log.debug('event code: {}'.format(event.__dict__))
      if event.code == 8192:
          log.error('The job crashed')
      log.debug('event code: {}'.format(event.code))
  
  
  scheduler = BlockingScheduler()
  scheduler.configure(executors=executors)
  scheduler.add_listener(scheduler_listener, EVENT_JOB_EXECUTED | 
  EVENT_JOB_ERROR)
  
  # snapshot
  scheduler.add_job(make_db_snapshot, trigger='cron',
                    name='DB snapshot', minute=SNAPSHOT['minute'],
                    hour=SNAPSHOT['hour'], args=[ZFS['dataset'], ARGS])
  
  try:
      scheduler.start()
  except (KeyboardInterrupt, SystemExit):
      exit(0)
  </code></pre>
  
  <p>This is where I need to exit:</p>
  
  <pre><code>def print_header():
      if not proc_is_running(DB['process_name']):
          log.error('DB process &lt;{0}&gt; is NOT running, exiting job'.
                    format(DB['process_name']))
          exit(5)
  
      log.info('{:=^70}'.format('='))
      ....
  </code></pre>
  
  <p>And this is what I get:</p>
  
  <pre><code>INFO: Running job "DB snapshot (trigger: cron[hour='*', minute='*/1'], next 
  run at: 2017-10-20 13:53:00 CEST)" (scheduled at 2017-10-20 13:52:00+02:00)
  DEBUG: checking if process mysqld is running
  ERROR: DB process &lt;mysqld&gt; is NOT running, exiting job
  ERROR: Job "DB snapshot (trigger: cron[hour='*', minute='*/1'], next run at: 
  2017-10-20 13:53:00 CEST)" raised an exception
  Traceback (most recent call last):
    File "/usr/local/lib/python3.5/dist-
    packages/apscheduler/executors/base.py", line 125, in run_job
      retval = job.func(*job.args, **job.kwargs)
    File "./db-backup", line 198, in make_db_snapshot
      print_header()
    File "./db-backup", line 289, in print_header
      exit(5)
    File "/usr/lib/python3.5/_sitebuiltins.py", line 26, in __call__
      raise SystemExit(code)
  SystemExit: 5
  DEBUG: event code: {'traceback': '  File "/usr/local/lib/python3.5/dist-
  packages/apscheduler/executors/base.py", line 125, in run_job\n    retval = 
  job.func(*job.args, **job.kwargs)\n  File "./db-backup", line 198, in 
  make_db_snapshot\n    print_header()\n  File "./db-backup", line 289, in 
  print_header\n    exit(5)\n  File "/usr/lib/python3.5/_sitebuiltins.py", 
  line 26, in __call__\n    raise SystemExit(code)\n', 'exception': 
  SystemExit(5,), 'retval': None, 'job_id': 
  'd0ba1527e68a460da44b4b4dde618552', 'code': 8192, 'scheduled_run_time': 
  datetime.datetime(2017, 10, 20, 13, 52, tzinfo=&lt;DstTzInfo 'Europe/Oslo' 
  CEST+2:00:00 DST&gt;), 'jobstore': 'default', 'alias': None}
  ERROR: The job crashed
  DEBUG: event code: 8192
  </code></pre>