import fcntl
import errno


def xioctl(fd, req, arg):
    """
    Wrapper around ioctl that polls it until it no longer returns EINTR
    """
    while True:
        try:
            r = fcntl.ioctl(fd, req, arg)
        except IOError as e:
            if e.errno != errno.EINTR:
                raise
            print("Waiting...")
        else:
            return r