def listen(self):
        """Listen to incoming clients until
        self._running is set to False
        """
        l = self.listener
        self._running = True
        try:
            while self._running:
                log.debug("Accept connection")
                c = l.accept()

                try:
                    action = c.recv()
                except EOFError:
                    c.close()
                    continue
                if isinstance(action, basestring):
                    args = ()
                    kwargs = {}
                else:
                    args = action.get('args', ())
                    kwargs = action.get('kwargs') or {}
                    action = action.get('action')


                log.info('Dispatch action "%s"' % action)
                method = getattr(self, action % 'dispatch_%s', None)
                if method:
                    try:
                        result = method(*args, **kwargs)
                    except Exception as err:
                        log.exception(err)
                        c.send({'error':True, 'message':'Exception in action %s - %s' % (action, err)})
                    else:
                        c.send({'error':False, 'message':'ok', 'result': result})
                else:
                    log.warn('No action %s' % action)
                    c.send({'error':True, 'message':'No action %s' % action})
                c.close()
        finally:
            self._listener = None
            l.close()

        log.info("Exiting event loop")
dataset/ETHPy150Open Anaconda-Platform/chalmers/chalmers/event_dispatcher.py/EventDispatcher.listen/swapped operands of `%`