# Path: pypot/utils/stoppablethread.py
# class StoppableLoopThread(StoppableThread):
#     """ LoopThread calling an update method at a pre-defined frequency.
# 
#     .. note:: This class does not mean to be accurate. The given frequency will be approximately followed - depending for instance on CPU load - and only reached if the update method takes less time than the chosen loop period.
# 
#     """
#     def __init__(self, frequency, update=None):
#         """
#         :params float frequency: called frequency of the :meth:`~pypot.stoppablethread.StoppableLoopThread.update` method
# 
#         """
#         StoppableThread.__init__(self)
# 
#         self.period = 1.0 / frequency
#         self._update = self.update if update is None else update
#         self._updated = threading.Event()
# 
#     def run(self):
#         """ Called the update method at the pre-defined frequency. """
#         make_update_loop(self, self._update)
# 
#     def update(self):
#         """ Update method called at the pre-defined frequency. """
#         pass


import logging
import numpy
from collections import defaultdict
from functools import partial
from threading import Lock
from ..utils.stoppablethread import StoppableLoopThread
    def update(self):
        """ Combined at a predefined frequency the request orders and affect them to the real motors. """
        with self.syncing:
            for m in self._motors:
                to_set = defaultdict(list)

                for p in self._prim:
                    for key, val in getattr(p.robot, m.name)._to_set.items():
                        to_set[key].append(val)

                for key, val in to_set.items():
                    if key == 'led':
                        colors = set(val)
                        if len(colors) > 1:
                            colors -= {'off'}
                        filtred_val = colors.pop()
                    else:
                        filtred_val = self._filter(val)

                    logger.debug('Combined %s.%s from %s to %s',
                                 m.name, key, val, filtred_val)
                    setattr(m, key, filtred_val)

            [p._synced.set() for p in self._prim]

    def stop(self):
        """ Stop the primitive manager. """
        for p in self.primitives[:]:
            p.stop()


# Path: pypot/utils/stoppablethread.py
# class StoppableLoopThread(StoppableThread):
#     """ LoopThread calling an update method at a pre-defined frequency.
# 
#     .. note:: This class does not mean to be accurate. The given frequency will be approximately followed - depending for instance on CPU load - and only reached if the update method takes less time than the chosen loop period.
# 
#     """
#     def __init__(self, frequency, update=None):
#         """
#         :params float frequency: called frequency of the :meth:`~pypot.stoppablethread.StoppableLoopThread.update` method
# 
#         """
#         StoppableThread.__init__(self)
# 
#         self.period = 1.0 / frequency
#         self._update = self.update if update is None else update
#         self._updated = threading.Event()
# 
#     def run(self):
#         """ Called the update method at the pre-defined frequency. """
#         make_update_loop(self, self._update)
# 
#     def update(self):
#         """ Update method called at the pre-defined frequency. """
#         pass


# Path: pypot/primitive/manager.py
import logging
import numpy
from collections import defaultdict
from functools import partial
from threading import Lock
from ..utils.stoppablethread import StoppableLoopThread

    def update(self):
        """ Combined at a predefined frequency the request orders and affect them to the real motors. """
        with self.syncing:
            for m in self._motors:
                to_set = defaultdict(list)

                for p in self._prim:
                    for key, val in getattr(p.robot, m.name)._to_set.items():
                        to_set[key].append(val)

                for key, val in to_set.items():
                    if key == 'led':
                        colors = set(val)
                        if len(colors) > 1:
                            colors -= {'off'}
                        filtred_val = colors.pop()
                    else:
                        filtred_val = self._filter(val)

                    logger.debug('Combined %s.%s from %s to %s',
                                 m.name, key, val, filtred_val)
                    setattr(m, key, filtred_val)

            [p._synced.set() for p in self._prim]

    def stop(self):
        """ Stop the primitive manager. """
        for p in self.primitives[:]:
            p.stop()


        StoppableLoopThread.stop(self)