import select


def read_line(f):
    """Read a single line from a file stream; return empty string on EOF"""
    buf = ''
    while not buf.endswith("\n"):
        r, w, e = select.select([f], [], [])
        if r:
            nextbyte = f.read(1)
            if not nextbyte:
                return ''
            buf += nextbyte
        else:
            break
    return buf