diff options
Diffstat (limited to 'meta/lib/oeqa/core/decorator/oetimeout.py')
-rw-r--r-- | meta/lib/oeqa/core/decorator/oetimeout.py | 40 |
1 files changed, 10 insertions, 30 deletions
diff --git a/meta/lib/oeqa/core/decorator/oetimeout.py b/meta/lib/oeqa/core/decorator/oetimeout.py index f85e7d9792..a247583f7f 100644 --- a/meta/lib/oeqa/core/decorator/oetimeout.py +++ b/meta/lib/oeqa/core/decorator/oetimeout.py | |||
@@ -1,12 +1,8 @@ | |||
1 | # Copyright (C) 2016 Intel Corporation | 1 | # Copyright (C) 2016 Intel Corporation |
2 | # Released under the MIT license (see COPYING.MIT) | 2 | # Released under the MIT license (see COPYING.MIT) |
3 | 3 | ||
4 | from . import OETestDecorator, registerDecorator | ||
5 | |||
6 | import signal | 4 | import signal |
7 | from threading import Timer | 5 | from . import OETestDecorator, registerDecorator |
8 | |||
9 | from oeqa.core.threaded import OETestRunnerThreaded | ||
10 | from oeqa.core.exception import OEQATimeoutError | 6 | from oeqa.core.exception import OEQATimeoutError |
11 | 7 | ||
12 | @registerDecorator | 8 | @registerDecorator |
@@ -14,32 +10,16 @@ class OETimeout(OETestDecorator): | |||
14 | attrs = ('oetimeout',) | 10 | attrs = ('oetimeout',) |
15 | 11 | ||
16 | def setUpDecorator(self): | 12 | def setUpDecorator(self): |
17 | self.logger.debug("Setting up a %d second(s) timeout" % self.oetimeout) | 13 | timeout = self.oetimeout |
18 | 14 | def _timeoutHandler(signum, frame): | |
19 | if isinstance(self.case.tc.runner, OETestRunnerThreaded): | 15 | raise OEQATimeoutError("Timed out after %s " |
20 | self.timeouted = False | ||
21 | def _timeoutHandler(): | ||
22 | self.timeouted = True | ||
23 | |||
24 | self.timer = Timer(self.oetimeout, _timeoutHandler) | ||
25 | self.timer.start() | ||
26 | else: | ||
27 | timeout = self.oetimeout | ||
28 | def _timeoutHandler(signum, frame): | ||
29 | raise OEQATimeoutError("Timed out after %s " | ||
30 | "seconds of execution" % timeout) | 16 | "seconds of execution" % timeout) |
31 | 17 | ||
32 | self.alarmSignal = signal.signal(signal.SIGALRM, _timeoutHandler) | 18 | self.logger.debug("Setting up a %d second(s) timeout" % self.oetimeout) |
33 | signal.alarm(self.oetimeout) | 19 | self.alarmSignal = signal.signal(signal.SIGALRM, _timeoutHandler) |
20 | signal.alarm(self.oetimeout) | ||
34 | 21 | ||
35 | def tearDownDecorator(self): | 22 | def tearDownDecorator(self): |
36 | if isinstance(self.case.tc.runner, OETestRunnerThreaded): | 23 | signal.alarm(0) |
37 | self.timer.cancel() | 24 | signal.signal(signal.SIGALRM, self.alarmSignal) |
38 | self.logger.debug("Removed Timer handler") | 25 | self.logger.debug("Removed SIGALRM handler") |
39 | if self.timeouted: | ||
40 | raise OEQATimeoutError("Timed out after %s " | ||
41 | "seconds of execution" % self.oetimeout) | ||
42 | else: | ||
43 | signal.alarm(0) | ||
44 | signal.signal(signal.SIGALRM, self.alarmSignal) | ||
45 | self.logger.debug("Removed SIGALRM handler") | ||