-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve timeout handling on POSIX and Windows for #521
* Windows tests were failing. The robotframework code was not working I replaced this with the older thread-based implmentation and cleanup the code for POSIX. Link: #521 Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
- Loading branch information
1 parent
a66817d
commit 02766cf
Showing
10 changed files
with
250 additions
and
186 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
File renamed without changes.
6 changes: 4 additions & 2 deletions
6
src/scancode/timeouts/robotframework.ABOUT → src/scancode/interrupt-robotframework.ABOUT
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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
about_resource: robotframework-3.0.2-py2-none-any.whl | ||
about_resource: interrup.py | ||
version: 3.0.2 | ||
download_url: https://pypi.python.org/packages/3e/79/d8b9a7ea833cf4f33d51c0d5f24b825ac72105bf30c147b472da10895143/robotframework-3.0.2.tar.gz#md5=ea49a54b9d7e38302712194e85c37eaa | ||
|
||
name: robotframework | ||
home_url: http://robotframework.org/ | ||
owner: Robot Framework Foundation | ||
dje_license: apache-2.0 | ||
notice_file: robotframework.NOTICE | ||
notice_file: interrupt-robotframework.NOTICE | ||
license_text_file: apache-2.0.LICENSE | ||
|
||
copyright: Copyright 2008-2015 Nokia Networks | ||
Copyright 2016- Robot Framework Foundation | ||
|
||
vcs_tool: git | ||
vcs_repository: https://github.com/robotframework/robotframework.git | ||
|
||
notes: some snippets and ideas were borrowed from the timeout implmentations. |
File renamed without changes.
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,7 @@ | ||
about_resource: interrupt.py | ||
author: Tomer Filiba | ||
homepage_url: http://tomerfiliba.com/recipes/Thread2/ | ||
license: public-domain | ||
notes: Per http://tomerfiliba.com/recipes/ | ||
All of the following are published as "public domain", or, if you prefer, | ||
under the MIT license. |
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,111 @@ | ||
Killable Threads | ||
August 13, 2006 | ||
By Tomer Filiba | ||
|
||
from http://tomerfiliba.com/recipes/Thread2/ | ||
|
||
Per http://tomerfiliba.com/recipes/ | ||
|
||
> All of the following are published as "public domain", or, if you prefer, | ||
under the MIT license. | ||
|
||
# Killable Threads | ||
|
||
The `thread2` module is an extension of the standard `threading` module, and provides | ||
the means to raise exceptions at the context of the given thread. You can use | ||
`raise_exc()` to raise an arbitrary exception, or call `terminate()` to raise | ||
`SystemExit` automatically. | ||
|
||
It uses the unexposed `PyThreadState_SetAsyncExc` function (via `ctypes`) to raise an | ||
exception in the context of the given thread. Inspired by the code of Antoon Pardon | ||
at http://mail.python.org/pipermail/python-list/2005-December/316143.html | ||
|
||
### Issues | ||
|
||
* The exception will be raised only when executing python bytecode. If your thread | ||
calls a native/built-in blocking function, the exception will be raised only when | ||
execution returns to the python code. | ||
|
||
* There is also an issue if the built-in function internally calls `PyErr_Clear()`, | ||
which would effectively cancel your pending exception. You can try to raise it again. | ||
|
||
* Only exception **types** can be raised safely. Exception instances are likely to | ||
cause unexpected behavior, and are thus restricted. | ||
|
||
* For example: `t1.raise_exc(TypeError)` and not `t1.raise_exc(TypeError("blah"))`. | ||
* IMHO it's a bug, and I reported it as one. For more info | ||
http://mail.python.org/pipermail/python-dev/2006-August/068158.html | ||
|
||
* I asked to expose this function in the built-in `thread` module, but since `ctypes` | ||
has become a standard library (as of 2.5), and this feature is not likely to be | ||
implementation-agnostic, it may be kept unexposed. | ||
|
||
## Code | ||
|
||
import threading | ||
import inspect | ||
import ctypes | ||
|
||
def _async_raise(tid, exctype): | ||
"""raises the exception, performs cleanup if needed""" | ||
if not inspect.isclass(exctype): | ||
raise TypeError("Only types can be raised (not instances)") | ||
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) | ||
if res == 0: | ||
raise ValueError("invalid thread id") | ||
elif res != 1: | ||
# """if it returns a number greater than one, you're in trouble, | ||
# and you should call it again with exc=NULL to revert the effect""" | ||
ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0) | ||
raise SystemError("PyThreadState_SetAsyncExc failed") | ||
|
||
class Thread(threading.Thread): | ||
def _get_my_tid(self): | ||
"""determines this (self's) thread id""" | ||
if not self.isAlive(): | ||
raise threading.ThreadError("the thread is not active") | ||
|
||
# do we have it cached? | ||
if hasattr(self, "_thread_id"): | ||
return self._thread_id | ||
|
||
# no, look for it in the _active dict | ||
for tid, tobj in threading._active.items(): | ||
if tobj is self: | ||
self._thread_id = tid | ||
return tid | ||
|
||
raise AssertionError("could not determine the thread's id") | ||
|
||
def raise_exc(self, exctype): | ||
"""raises the given exception type in the context of this thread""" | ||
_async_raise(self._get_my_tid(), exctype) | ||
|
||
def terminate(self): | ||
"""raises SystemExit in the context of the given thread, which should | ||
cause the thread to exit silently (unless caught)""" | ||
self.raise_exc(SystemExit) | ||
|
||
|
||
## Example | ||
|
||
|
||
>>> import time | ||
>>> from thread2 import Thread | ||
>>> | ||
>>> def f(): | ||
... try: | ||
... while True: | ||
... time.sleep(0.1) | ||
... finally: | ||
... print "outta here" | ||
... | ||
>>> t = Thread(target = f) | ||
>>> t.start() | ||
>>> t.isAlive() | ||
True | ||
>>> t.terminate() | ||
>>> t.join() | ||
outta here | ||
>>> t.isAlive() | ||
False |
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
Oops, something went wrong.