import ctypes
import inspect
import logging
from threading import Thread
# 函数执行超时装饰器
def timelimited(timeout):
def decorator(function):
def decorator2(*args,**kwargs):
class TimeoutException(Exception):
pass
def stop_thread(thread):
def _async_raise(tid, exctype):
"""raises the exception, performs cleanup if needed"""
tid = ctypes.c_long(tid)
if not inspect.isclass(exctype):
exctype = type(exctype)
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,
函数执行超时装饰器(python3)
最新推荐文章于 2024-04-15 09:47:22 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)