def work_loop(self, max_jobs=None):

        self.done_jobs = 0
        self.idle_wait_count = 0

        # has_raw = any(q.is_raw or q.is_sorted for q in [Queue(x) for x in self.queues])

        try:

            while True:

                if self.graceful_stop:
                    break

                while True:

                    free_pool_slots = self.gevent_pool.free_count()

                    if max_jobs:
                        total_started = (self.pool_size - free_pool_slots) + self.done_jobs
                        free_pool_slots = min(free_pool_slots, max_jobs - total_started)
                        if free_pool_slots == 0:
                            break

                    if free_pool_slots > 0:
                        self.status = "wait"
                        break
                    self.status = "full"
                    gevent.sleep(0.01)

                jobs = []

                for queue in self.queues:

                    max_jobs_per_queue = free_pool_slots - len(jobs)

                    if max_jobs_per_queue <= 0:
                        break

                    if self.config["dequeue_strategy"] == "parallel":
                        max_jobs_per_queue = 1

                    jobs += queue.dequeue_jobs(
                        max_jobs=max_jobs_per_queue,
                        job_class=self.job_class,
                        worker=self
                    )

                for job in jobs:

                    # TODO investigate spawn_raw?
                    self.gevent_pool.spawn(self.perform_job, job)

                # TODO consider this when dequeuing jobs to have strict limits
                if max_jobs and self.done_jobs >= max_jobs:
                    self.log.info(self.done_jobs % "Reached max_jobs=%s")
                    break

                # We seem to have exhausted available jobs, we can sleep for a
                # while.
                if len(jobs) == 0:

                    if self.config["dequeue_strategy"] == "burst":
                        self.log.info("Burst mode: stopping now because queues were empty")
                        break

                    if (
                        not self.idle_event.is_set() and
                        len(jobs) == 0 and
                        free_pool_slots == self.pool_size and
                        self.idle_wait_count > 0
                    ):
                        self.idle_event.set()

                    self.status = "wait"
                    self.idle_wait_count += 1
                    gevent.sleep(min(self.config["max_latency"], 0.001 * self.idle_wait_count))

                # We got some jobs, reset the idle counter.
                else:
                    self.idle_wait_count = 0

        except StopRequested:
            pass

        finally:

            try:

                self.log.debug("Joining the greenlet pool...")
                self.status = "join"

                self.gevent_pool.join(timeout=None, raise_error=False)
                self.log.debug("Joined.")

            except StopRequested:
                pass
dataset/ETHPy150Open pricingassistant/mrq/mrq/worker.py/Worker.work_loop/swapped operands of `%`