ÿØÿà JFIF ` ` ÿþxØ
| Server IP : 109.234.164.53 / Your IP : 216.73.216.110 Web Server : Apache System : Linux cervelle.o2switch.net 4.18.0-553.32.1.lve.el8.x86_64 #1 SMP Thu Dec 19 13:14:03 UTC 2024 x86_64 User : computer3 ( 1098) PHP Version : 7.1.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /opt/alt/python37/lib/python3.7/site-packages/paste/util/ |
Upload File : |
"""
Kill a thread, from http://sebulba.wikispaces.com/recipe+thread2
"""
import types
try:
import ctypes
except ImportError:
raise ImportError(
"You cannot use paste.util.killthread without ctypes installed")
if not hasattr(ctypes, 'pythonapi'):
raise ImportError(
"You cannot use paste.util.killthread without ctypes.pythonapi")
def async_raise(tid, exctype):
"""raises the exception, performs cleanup if needed.
tid is the value given by thread.get_ident() (an integer).
Raise SystemExit to kill a thread."""
if not isinstance(exctype, (types.ClassType, type)):
raise TypeError("Only types can be raised (not instances)")
if not isinstance(tid, int):
raise TypeError("tid must be an integer")
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(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(ctypes.c_long(tid), 0)
raise SystemError("PyThreadState_SetAsyncExc failed")