def blocking_read(fd, n):
    io = BytesIO()
    read_amount = 0
    while (read_amount < n):
        data = os.read(fd, (n - read_amount))
        if (not data):
            raise IOError('FD closed before all bytes read')
        read_amount += len(data)
        io.write(data)
    return io.getvalue()
def blocking_read(fd, n):
    io = BytesIO()
    read_amount = 0
    while (read_amount < n):
        data = os.read(fd, (n - read_amount))
        if (not data):
            raise IOError('FD closed before all bytes read')
        read_amount += len(data)
        io.write(data)
    return io.getvalue()