You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

timeout_utils.py 753 B

4 years ago
123456789101112131415161718192021222324252627282930313233343536
  1. import platform
  2. if platform.system() != "Windows":
  3. import signal
  4. else:
  5. signal = None
  6. __all__ = ['TimeoutError', 'WindowsError', 'TimeoutContext']
  7. class TimeoutError(Exception):
  8. pass
  9. class WindowsError(Exception):
  10. pass
  11. class TimeoutContext():
  12. """Timeout class using ALARM signal."""
  13. def __init__(self, sec):
  14. self.sec = sec
  15. def __enter__(self):
  16. if signal is None:
  17. raise WindowsError("Windows is not supported for this test")
  18. signal.signal(signal.SIGALRM, self.raise_timeout)
  19. signal.alarm(self.sec)
  20. def __exit__(self, *args):
  21. signal.alarm(0) # disable alarm
  22. def raise_timeout(self, *args):
  23. raise TimeoutError("A timeout error have been raised.")

TensorLayer3.0 是一款兼容多种深度学习框架为计算后端的深度学习库。计划兼容TensorFlow, Pytorch, MindSpore, Paddle.