<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def animate_cycle(self, colors, groups=('LEFT', 'RIGHT'), sleeptime=0.5, duration=5, block=True):
 """ Cycle ``groups`` LEDs through ``colors``. Do this in a loop where we display each color for ``sleeptime`` seconds. Animate for ``duration`` seconds. If ``duration`` is None animate for forever. Example: .. code-block:: python from ev3dev2.led import Leds leds = Leds() leds.animate_cyle(('RED', 'GREEN', 'AMBER')) """

        def _animate_cycle():
            index = 0
            max_index = len(colors)
            start_time = dt.datetime.now()

            while True:
                for group in groups:
                    self.set_color(group, colors[index])

                index += 1

                if index == max_index:
                    index = 0

                if self.animate_thread_stop or duration_expired(start_time, duration):
                    break

                sleep(sleeptime)

            self.animate_thread_stop = False
            self.animate_thread_id = None

        self.animate_stop()

        if block:
            _animate_cycle()
        else:
            self.animate_thread_id = _thread.start_new_thread(_animate_cycle, ())