def run(self):
        """
        Wait for either a call to stop() or for a data to be available
        on the channel and then call handle_message. And loop over.
        """
        # Initialize poll()
        fd        = self._channel.fileno()
        waitset   = select.poll()
        eventmask = select.POLLIN | select.POLLERR \
                    | select.POLLHUP | select.POLLPRI
        waitset.register(fd, eventmask)
        waitset.register(self.__terms[0], eventmask)

        while 1:
            exit_loop = False
            for fd_, evt in waitset.poll():
                if fd_ != fd:
                    # Received sthg on the __terms pipe
                    exit_loop = True
                    break
                if evt != select.POLLIN:
                    # Receive something on the channel, but not a normal
                    # data (probably a HUP)
                    exit_loop = True
                    break

            if exit_loop:
                break

            # Error while receiving => term thread
            data = self._recv()

            # Call handle_message (dump the exceptions, but ignore them)
            try:
                self.handle_message(data)
            except:
                traceback.print_exc()
        # End while

        Wait for either a call to stop() or for a data to be available
        on the channel and then call handle_message. And loop over.
        
recipes/Python/576520_Multithreaded_MultiplexerDemultiplexer_allow/recipe-576520.py