Extracting lines from a bytearray
You have overlooked a corner case: while you normally treat \r\n as a single separator, this not the case when the two bytes are split between blocks.
splitlines could handle the universal newlines for you.


Here's what I came up with; still not very pretty I'm afraid. Initialize self.carry_cr = False in constructor.

def emit(self):
    buf = self.buf
    if buf:
        # skip \n if previous buffer ended with \r
        if self.carry_cr and buf.startswith(b'\n'):
            del buf[0]
        self.carry_cr = False

    lines = buf.splitlines()
    if buf:
        if self.is_open and not buf.endswith((b'\r', b'\n')):
            buf = lines.pop()
        else:
            if buf.endswith(b'\r'):
                self.carry_cr = True
            del buf[:]
    self.buf = buf

    self.emitted_this_cycle = False
    if lines:
        self.emitted_this_cycle = True
        for line in lines:
            yield (self.fd, line.decode(self.enc).rstrip())
    if not self.is_open:
        self.emitted_this_cycle = True
        yield (self.fd, None)