summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r--meta/lib/oeqa/utils/decorators.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py
index 61a1a739ea..b9fc76c9ee 100644
--- a/meta/lib/oeqa/utils/decorators.py
+++ b/meta/lib/oeqa/utils/decorators.py
@@ -11,6 +11,8 @@ import logging
11import sys 11import sys
12import unittest 12import unittest
13import threading 13import threading
14import signal
15from functools import wraps
14 16
15#get the "result" object from one of the upper frames provided that one of these upper frames is a unittest.case frame 17#get the "result" object from one of the upper frames provided that one of these upper frames is a unittest.case frame
16class getResults(object): 18class getResults(object):
@@ -160,3 +162,27 @@ def LogResults(original_class):
160 162
161 original_class.run = run 163 original_class.run = run
162 return original_class 164 return original_class
165
166class TimeOut(BaseException):
167 pass
168
169def timeout(seconds):
170 def decorator(fn):
171 if hasattr(signal, 'alarm'):
172 @wraps(fn)
173 def wrapped_f(*args, **kw):
174 current_frame = sys._getframe()
175 def raiseTimeOut(signal, frame):
176 if frame is not current_frame:
177 raise TimeOut('%s seconds' % seconds)
178 prev_handler = signal.signal(signal.SIGALRM, raiseTimeOut)
179 try:
180 signal.alarm(seconds)
181 return fn(*args, **kw)
182 finally:
183 signal.alarm(0)
184 signal.signal(signal.SIGALRM, prev_handler)
185 return wrapped_f
186 else:
187 return fn
188 return decorator \ No newline at end of file