_utils.py 761 B

12345678910111213141516171819202122232425262728
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the MIT License. See the LICENSE file in the root of this
  3. # repository for complete details.
  4. """
  5. Generic utilities.
  6. """
  7. from __future__ import absolute_import, division, print_function
  8. import errno
  9. def until_not_interrupted(f, *args, **kw):
  10. """
  11. Retry until *f* succeeds or an exception that isn't caused by EINTR occurs.
  12. :param callable f: A callable like a function.
  13. :param *args: Positional arguments for *f*.
  14. :param **kw: Keyword arguments for *f*.
  15. """
  16. while True:
  17. try:
  18. return f(*args, **kw)
  19. except (IOError, OSError) as e:
  20. if e.args[0] == errno.EINTR:
  21. continue
  22. raise