docs: def poll_queue(job_id, pid, poll_time):
      """
      Check the queue of executing/submitted jobs and exit when there is
      a free slot.
      """
      if config.distribution.serialize_jobs:
          first_time = True
          while True:
              jobs = logs.dbcmd(GET_JOBS)
              failed = [job.id for job in jobs if not psutil.pid_exists(job.pid)]
              if failed:
                  logs.dbcmd("UPDATE job SET status='failed', is_running=0 "
                             "WHERE id in (?X)", failed)
              elif any(job.id < job_id for job in jobs):
                  if first_time:
                      logs.LOG.warn('Waiting for jobs %s', [j.id for j in jobs])
                      logs.dbcmd('update_job', job_id,
                                 {'status': 'submitted', 'pid': pid})
                      first_time = False
                  time.sleep(poll_time)
              else:
                  break
      logs.dbcmd('update_job', job_id, {'status': 'executing', 'pid': _PID})