Robot Framework Integrated Development Environment (RIDE)
ironpython.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import sys
17 import threading
18 
19 from System.Threading import Thread, ThreadStart
20 
21 
22 class Timeout():
23 
24  def __init__(self, timeout, error):
25  self._timeout_timeout = timeout
26  self._error_error = error
27 
28  def execute(self, runnable):
29  runner = Runner(runnable)
30  thread = Thread(ThreadStart(runner))
31  thread.IsBackground = True
32  thread.Start()
33  if not thread.Join(self._timeout_timeout * 1000):
34  thread.Abort()
35  raise self._error_error
36  return runner.get_result()
37 
38 
39 class Runner():
40 
41  def __init__(self, runnable):
42  self._runnable_runnable = runnable
43  self._result_result = None
44  self._error_error = None
45 
46  def __call__(self):
47  threading.currentThread().setName('RobotFrameworkTimeoutThread')
48  try:
49  self._result_result = self._runnable_runnable()
50  except:
51  self._error_error = sys.exc_info()
52 
53  def get_result(self):
54  if not self._error_error:
55  return self._result_result
56  # `exec` used to avoid errors with easy_install on Python 3:
57  # https://github.com/robotframework/robotframework/issues/2785
58  exec('raise self._error[0], self._error[1], self._error[2]')