from queue import Queue
from subprocess import Popen, PIPE
from threading import Thread


def follow_file(fn, max_lines=100):
    """
    Return a Queue that is fed lines (up to max_lines) from the given file (fn)
    continuously

    The implementation given here was inspired by
    http://stackoverflow.com/questions/12523044/how-can-i-tail-a-log-file-in-python
    """
    fq = Queue(maxsize=max_lines)

    # Declare the helper routine
    def _follow_file_thread(fn, fq):
        # Use system tail with name-based following and retry
        p = Popen(["tail", "-F", fn], stdout=PIPE)

        # Loop forever on pulling data from tail
        line = True
        while line:
            line = p.stdout.readline()
            fq.put(line)

    # Spawn a thread to read data from tail
    Thread(target=_follow_file_thread, args=(fn, fq)).start()

    # Return the queue
    return fq

from queue import Queue
from subprocess import Popen, PIPE
from threading import Thread


def follow_file(fn, max_lines=100):
    """
    Return a Queue that is fed lines (up to max_lines) from the given file (fn)
    continuously

    The implementation given here was inspired by
    http://stackoverflow.com/questions/12523044/how-can-i-tail-a-log-file-in-python
    """
    fq = Queue(maxsize=max_lines)

    # Declare the helper routine
    def _follow_file_thread(fn, fq):
        # Use system tail with name-based following and retry
        p = Popen(["tail", "-F", fn], stdout=PIPE)

        # Loop forever on pulling data from tail
        line = True
        while line:
            line = p.stdout.readline().decode('utf-8')
            fq.put(line)

    # Spawn a thread to read data from tail
    Thread(target=_follow_file_thread, args=(fn, fq)).start()

    # Return the queue
    return fq

Make sure that follow-file decodes utf-8 from its input
Make sure that follow-file decodes utf-8 from its input

Signed-off-by: Jason Bernardino Alonso <f71c42a1353bbcdbe07e24c2a1c893f8ea1d05ee@hackorp.com>

  from queue import Queue
  from subprocess import Popen, PIPE
  from threading import Thread
  
  
  def follow_file(fn, max_lines=100):
      """
      Return a Queue that is fed lines (up to max_lines) from the given file (fn)
      continuously
  
      The implementation given here was inspired by
      http://stackoverflow.com/questions/12523044/how-can-i-tail-a-log-file-in-python
      """
      fq = Queue(maxsize=max_lines)
  
      # Declare the helper routine
      def _follow_file_thread(fn, fq):
          # Use system tail with name-based following and retry
          p = Popen(["tail", "-F", fn], stdout=PIPE)
  
          # Loop forever on pulling data from tail
          line = True
          while line:
-             line = p.stdout.readline()
+             line = p.stdout.readline().decode('utf-8')
              fq.put(line)
  
      # Spawn a thread to read data from tail
      Thread(target=_follow_file_thread, args=(fn, fq)).start()
  
      # Return the queue
      return fq
  
Make sure that follow-file decodes utf-8 from its input
## Code Before:
from queue import Queue
from subprocess import Popen, PIPE
from threading import Thread


def follow_file(fn, max_lines=100):
    """
    Return a Queue that is fed lines (up to max_lines) from the given file (fn)
    continuously

    The implementation given here was inspired by
    http://stackoverflow.com/questions/12523044/how-can-i-tail-a-log-file-in-python
    """
    fq = Queue(maxsize=max_lines)

    # Declare the helper routine
    def _follow_file_thread(fn, fq):
        # Use system tail with name-based following and retry
        p = Popen(["tail", "-F", fn], stdout=PIPE)

        # Loop forever on pulling data from tail
        line = True
        while line:
            line = p.stdout.readline()
            fq.put(line)

    # Spawn a thread to read data from tail
    Thread(target=_follow_file_thread, args=(fn, fq)).start()

    # Return the queue
    return fq

## Instruction:
Make sure that follow-file decodes utf-8 from its input
## Code After:
from queue import Queue
from subprocess import Popen, PIPE
from threading import Thread


def follow_file(fn, max_lines=100):
    """
    Return a Queue that is fed lines (up to max_lines) from the given file (fn)
    continuously

    The implementation given here was inspired by
    http://stackoverflow.com/questions/12523044/how-can-i-tail-a-log-file-in-python
    """
    fq = Queue(maxsize=max_lines)

    # Declare the helper routine
    def _follow_file_thread(fn, fq):
        # Use system tail with name-based following and retry
        p = Popen(["tail", "-F", fn], stdout=PIPE)

        # Loop forever on pulling data from tail
        line = True
        while line:
            line = p.stdout.readline().decode('utf-8')
            fq.put(line)

    # Spawn a thread to read data from tail
    Thread(target=_follow_file_thread, args=(fn, fq)).start()

    # Return the queue
    return fq
