def stop(self):
        """Stop the worker threads and close the channel"""
        ReceiverThread.stop(self)

        #
        # No lock because the listening thread is dead already (no new
        # thread)
        #

        # Clearing job queue
        if self.__workq is not None:
            while 1:
                try:
                    self.__workq.get_nowait()
                except Queue.Empty:
                    break

        # Stopping workers
        if self.__nworkers is not None:
            for i in range(self.__nworkers):
                self.__workq.put(SENTINEL)
            for thr in self.__workers:
                thr.join()
        else:
            while self.__workers:
                xid, thr = self.__workers.popitem()
                thr.join()
Stop the worker threads and close the channel
recipes/Python/576520_Multithreaded_MultiplexerDemultiplexer_allow/recipe-576520.py