'Executes jobs on schedule.'

def _main_loop(self):

    logger.info('Scheduler    started')
    self._notify_listeners(SchedulerEvent(EVENT_SCHEDULER_START))
    self._wakeup.clear()
    while (not self._stopped):
        logger.debug('Looking    for    jobs    to    run')
        now = datetime.now()
        next_wakeup_time = self._process_jobs(now)
        if (next_wakeup_time is not None):
            wait_seconds = time_difference(next_wakeup_time, now)
            logger.debug('Next    wakeup    is    due    at    %s    (in    %f    seconds)', next_wakeup_time, wait_seconds)
            try:
                self._wakeup.wait(wait_seconds)
            except IOError:
                pass
            self._wakeup.clear()
        elif self.standalone:
            logger.debug('No    jobs    left;    shutting    down    scheduler')
            self.shutdown()
            break
        else:
            logger.debug('No    jobs;    waiting    until    a    job    is    added')
            try:
                self._wakeup.wait()
            except IOError:
                pass
            self._wakeup.clear()
    logger.info('Scheduler    has    been    shut    down')
    self._notify_listeners(SchedulerEvent(EVENT_SCHEDULER_SHUTDOWN))
