-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up timeouts on Jython. Related to #1931.
Now that IronPython has its own timeout implementation, Jython was the only one using timeoutthread module and nobody used stoppablethread it used when not run on Jython. Moved Jython related stuff to new module and removed not used modules. Jython and IronPython thread usage is very similar, and it would be pretty easy to create facades to avoid duplication. Decided to keep them separate because that would require more code, including a new module, and added abstraction level would make things a little more complicated.
- Loading branch information
1 parent
b40b8bf
commit cdfb783
Showing
6 changed files
with
63 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
from java.lang import Thread, Runnable | ||
|
||
from robot.errors import TimeoutError | ||
|
||
|
||
class Timeout(object): | ||
|
||
def __init__(self, timeout, error): | ||
self._timeout = timeout | ||
self._error = error | ||
|
||
def execute(self, runnable): | ||
runner = Runner(runnable) | ||
thread = Thread(runner, name='RobotFrameworkTimeoutThread') | ||
thread.setDaemon(True) | ||
thread.start() | ||
thread.join(int(self._timeout * 1000)) | ||
if thread.isAlive(): | ||
thread.stop() | ||
raise TimeoutError(self._error) | ||
return runner.get_result() | ||
|
||
|
||
class Runner(Runnable): | ||
|
||
def __init__(self, runnable): | ||
self._runnable = runnable | ||
self._result = None | ||
self._error = None | ||
|
||
def run(self): | ||
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] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.