Python threading.Thread 模块,_Thread__stop() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用threading.Thread._Thread__stop()

项目:Malicious_Domain_Whois    作者:h-j-13    | 项目源码 | 文件源码
def timelimited(timeout):
    """
    :param timeout:?????int/float?
    ?????????????????????????
    ??????????,?Rasie???????????
    """
    def decorator(function):
        def decorator2(*args, **kwargs):
            class TimeLimited(Thread):
                def __init__(self, _error=None, ):
                    Thread.__init__(self)
                    self._error = _error
                    self.result = None
                def run(self):
                    try:
                        self.result = function(*args, **kwargs)
                    except Exception, e:
                        self._error = e
                def _stop(self):
                    if self.isAlive():
                        ThreadStop = Thread._Thread__stop
                        ThreadStop(self)
            t = TimeLimited()
            t.setDaemon(True)  # ????
            t.start()
            t.join(timeout)
            if isinstance(t._error, TimeoutException):
                t._stop()
                return 'ERROR -1'  # ??
            if t.isAlive():
                t._stop()
                return 'ERROR -1'  # ??
            if t._error is None:
                t._stop()
                return t.result
        return decorator2
    return decorator
项目:Malicious_Domain_Whois    作者:h-j-13    | 项目源码 | 文件源码
def timelimited(timeout):
    def decorator(function):
        def decorator2(*args, **kwargs):
            class TimeLimited(Thread):
                def __init__(self, _error=None, ):
                    Thread.__init__(self)
                    self._error = _error
                    self.result = None
                def run(self):
                    try:
                        self.result = function(*args, **kwargs)
                    except Exception, e:
                        self._error = e
                def _stop(self):
                    if self.isAlive():
                        ThreadStop = Thread._Thread__stop
                        ThreadStop(self)
            t = TimeLimited()
            t.setDaemon(True)  # ????
            t.start()
            t.join(timeout)
            if isinstance(t._error, TimeoutException):
                t._stop()
                return 'ERROR -1'  # ??
            if t.isAlive():
                t._stop()
                return 'ERROR -1'  # ??
            if t._error is None:
                t._stop()
                return t.result
        return decorator2
    return decorator
项目:Malicious_Domain_Whois    作者:h-j-13    | 项目源码 | 文件源码
def timelimited(timeout):
    def decorator(function):
        def decorator2(*args, **kwargs):
            class TimeLimited(Thread):
                def __init__(self, _error=None, ):
                    Thread.__init__(self)
                    self._error = _error
                    self.result = None
                def run(self):
                    try:
                        self.result = function(*args, **kwargs)
                    except Exception, e:
                        self._error = e
                def _stop(self):
                    if self.isAlive():
                        ThreadStop = Thread._Thread__stop
                        ThreadStop(self)
            t = TimeLimited()
            t.setDaemon(True)  # ????
            t.start()
            t.join(timeout)
            if isinstance(t._error, TimeoutException):
                t._stop()
                return 'ERROR -1'  # ??
            if t.isAlive():
                t._stop()
                return 'ERROR -1'  # ??
            if t._error is None:
                t._stop()
                return t.result
        return decorator2
    return decorator
项目:MyLib    作者:h-j-13    | 项目源码 | 文件源码
def timelimited(timeout):
    """
    :param timeout:?????int/float?
    ?????????????????????????
    ??????????,?Rasie???????????
    """
    def decorator(function):
        def decorator2(*args, **kwargs):
            class TimeLimited(Thread):
                def __init__(self, _error=None, ):
                    Thread.__init__(self)
                    self._error = _error
                    self.result = None
                def run(self):
                    try:
                        self.result = function(*args, **kwargs)
                    except Exception, e:
                        self._error = e
                def _stop(self):
                    if self.isAlive():
                        ThreadStop = Thread._Thread__stop
                        ThreadStop(self)
            t = TimeLimited()
            t.setDaemon(True)  # ????
            t.start()
            t.join(timeout)
            if isinstance(t._error, TimeoutException):
                t._stop()
                return 'ERROR -1'  # ??
            if t.isAlive():
                t._stop()
                return 'ERROR -1'  # ??
            if t._error is None:
                t._stop()
                return t.result
        return decorator2
    return decorator