def retry_on_eintr(function, *args, **kw):
    """Run a function and retry it while getting EINTR errors"""
    while True:
        try:
            return function(*args, **kw)
        except IOError as e:
            if e.errno != errno.EINTR:
                raise
Run a function and retry it while getting EINTR errors
stackoverflow/venv/lib/python3.6/site-packages/scrapy/utils/python.py