oetimeout.py 848 B

12345678910111213141516171819202122232425262728
  1. #
  2. # Copyright (C) 2016 Intel Corporation
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. import signal
  7. from . import OETestDecorator, registerDecorator
  8. from oeqa.core.exception import OEQATimeoutError
  9. @registerDecorator
  10. class OETimeout(OETestDecorator):
  11. attrs = ('oetimeout',)
  12. def setUpDecorator(self):
  13. timeout = self.oetimeout
  14. def _timeoutHandler(signum, frame):
  15. raise OEQATimeoutError("Timed out after %s "
  16. "seconds of execution" % timeout)
  17. self.logger.debug("Setting up a %d second(s) timeout" % self.oetimeout)
  18. self.alarmSignal = signal.signal(signal.SIGALRM, _timeoutHandler)
  19. signal.alarm(self.oetimeout)
  20. def tearDownDecorator(self):
  21. signal.alarm(0)
  22. signal.signal(signal.SIGALRM, self.alarmSignal)
  23. self.logger.debug("Removed SIGALRM handler")