root/galaxy-central/eggs/Paste-1.6-py2.6.egg/paste/util/killthread.py

リビジョン 3, 1.0 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1"""
2Kill a thread, from http://sebulba.wikispaces.com/recipe+thread2
3"""
4import types
5try:
6    import ctypes
7except ImportError:
8    raise ImportError(
9        "You cannot use paste.util.killthread without ctypes installed")
10
11def async_raise(tid, exctype):
12    """raises the exception, performs cleanup if needed.
13
14    tid is the value given by thread.get_ident() (an integer).
15    Raise SystemExit to kill a thread."""
16    if not isinstance(exctype, (types.ClassType, type)):
17        raise TypeError("Only types can be raised (not instances)")
18    if not isinstance(tid, int):
19        raise TypeError("tid must be an integer")
20    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
21    if res == 0:
22        raise ValueError("invalid thread id")
23    elif res != 1:
24        # """if it returns a number greater than one, you're in trouble,
25        # and you should call it again with exc=NULL to revert the effect"""
26        ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
27        raise SystemError("PyThreadState_SetAsyncExc failed")
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。