<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _wait_for_new_tasks(self, timeout=0, batch_timeout=0):
 """ Check activity channel and wait as necessary. This method is also used to slow down the main processing loop to reduce the effects of rapidly sending Redis commands. This method will exit for any of these conditions: 1. _did_work is True, suggests there could be more work pending 2. Found new queue and after batch timeout. Note batch timeout can be zero so it will exit immediately. 3. Timeout seconds have passed, this is the maximum time to stay in this method """


        new_queue_found = False
        start_time = batch_exit = time.time()
        while True:
            # Check to see if batch_exit has been updated
            if batch_exit > start_time:
                pubsub_sleep = batch_exit - time.time()
            else:
                pubsub_sleep = start_time + timeout - time.time()
            message = self._pubsub.get_message(timeout=0 if pubsub_sleep < 0 or
                                               self._did_work
                                               else pubsub_sleep)

            # Pull remaining messages off of channel
            while message:
                if message['type'] == 'message':
                    new_queue_found, batch_exit = self._process_queue_message(
                        message['data'], new_queue_found, batch_exit,
                        start_time, timeout, batch_timeout
                    )

                message = self._pubsub.get_message()

            if self._did_work:
                break   # Exit immediately if we did work during the last
                        # execution loop because there might be more work to do
            elif time.time() >= batch_exit and new_queue_found:
                break   # After finding a new queue we can wait until the
                        # batch timeout expires
            elif time.time() - start_time > timeout:
                break