Skip to content

Commit

Permalink
Avoid problems with timeouts on IronPython by using .NET theads (#1931).
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkaklarck committed Feb 25, 2015
1 parent 89d9d6a commit b40b8bf
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/robot/running/timeouts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
IRONPYTHON, JYTHON, WINDOWS)
from robot.errors import TimeoutError, DataError, FrameworkError

if IRONPYTHON or JYTHON:
if IRONPYTHON:
from .ironpython import Timeout
elif JYTHON:
from .timeoutthread import Timeout
elif WINDOWS:
from .timeoutwin import Timeout
Expand Down
56 changes: 56 additions & 0 deletions src/robot/running/timeouts/ironpython.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2008-2015 Nokia Solutions and Networks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import threading

from System.Threading import Thread, ThreadStart

from robot.errors import TimeoutError


class Timeout(object):

def __init__(self, timeout, error):
self._timeout = timeout * 1000
self._error = error

def execute(self, runnable):
runner = Runner(runnable)
thread = Thread(ThreadStart(runner))
thread.Start()
if thread.Join(self._timeout):
return runner.get_result()
thread.Abort()
raise TimeoutError(self._error)


class Runner(object):

def __init__(self, runnable):
self._runnable = runnable
self._result = None
self._error = None

def __call__(self):
threading.currentThread().setName('RobotFrameworkTimeoutThread')
try:
self._result = self._runnable()
except:
self._error = sys.exc_info()

def get_result(self):
if not self._error:
return self._result
raise self._error[0], self._error[1], self._error[2]

0 comments on commit b40b8bf

Please sign in to comment.