Set the global mode to :attr:`IDLE` and wait for workers to stop.

        This can wait arbitrarily long before returning.  The worst
        case in "normal" usage involves waiting five minutes for a
        "lost" job to expire; a well-behaved but very-long-running job
        can extend its own lease further, and this function will not
        return until that job finishes (if ever).

        .. deprecated:: 0.4.5
            There isn't an obvious use case for this function, and its
            "maybe wait forever for something out of my control" nature
            makes it hard to use in real code.  Polling all of the work
            specs and their :meth:`num_pending` in application code if
            you really needed this operation would have the same
            semantics and database load.

def idle_all_workers(self):
        '''Set the global mode to :attr:`IDLE` and wait for workers to stop.

        This can wait arbitrarily long before returning.  The worst
        case in "normal" usage involves waiting five minutes for a
        "lost" job to expire; a well-behaved but very-long-running job
        can extend its own lease further, and this function will not
        return until that job finishes (if ever).

        .. deprecated:: 0.4.5
            There isn't an obvious use case for this function, and its
            "maybe wait forever for something out of my control" nature
            makes it hard to use in real code.  Polling all of the work
            specs and their :meth:`num_pending` in application code if
            you really needed this operation would have the same
            semantics and database load.

        '''
        self.set_mode(self.IDLE)
        while 1:
            num_pending = dict()
            for work_spec_name in self.registry.pull(NICE_LEVELS).keys():
                num_pending[work_spec_name] = self.num_pending(work_spec_name)
            if sum(num_pending.values()) == 0:
                break
            logger.warn('waiting for pending work_units: %r', num_pending)
            time.sleep(1)