Start a thread logging output from pipe

def _log_thread(self, pipe, queue):
        """
        Start a thread logging output from pipe
        """

        # thread function to log subprocess output (LOG is a queue)
        def enqueue_output(out, q):
            for line in iter(out.readline, b''):
                q.put(line.rstrip())
            out.close()

        # start thread
        t = threading.Thread(target=enqueue_output,
                                  args=(pipe, queue))
        t.daemon = True  # thread dies with the program
        t.start()
        self.threads.append(t)