def run(self):
        '''Work on jobs'''
        # Register signal handlers
        self.signals()

        # Start listening
        with self.listener():
            try:
                generator = self.jobs()
                while not self.shutdown:
                    self.pool.wait_available()
                    job = next(generator)
                    if job:
                        # For whatever reason, doing imports within a greenlet
                        # (there's one implicitly invoked in job.process), was
                        # throwing exceptions. The hacky way to get around this
                        # is to force the import to happen before the greenlet
                        # is spawned.
                        job.klass
                        greenlet = gevent.Greenlet(self.process, job)
                        self.greenlets[job.jid] = greenlet
                        self.pool.start(greenlet)
                    else:
                        logger.debug('Sleeping for %fs' % self.interval)
                        gevent.sleep(self.interval)
            except StopIteration:
                logger.info('Exhausted jobs')
            finally:
                logger.info('Waiting for greenlets to finish')
                self.pool.join()
def run ( self ) : self . signals ( ) with self . listener ( ) : try : generator = self . jobs ( ) while not self . shutdown : self . pool . wait_available ( ) job = next ( generator ) if job : job . klass greenlet = gevent . Greenlet ( self . process , job ) self . greenlets [ job . jid ] = greenlet self . pool . start ( greenlet ) else : logger . debug ( 'Sleeping for %fs' % self . interval ) gevent . sleep ( self . interval ) except StopIteration : logger . info ( 'Exhausted jobs' ) finally : logger . info ( 'Waiting for greenlets to finish' ) self . pool . join ( )
Work on jobs