python继承threading.Thread实现有返回值的子类

继承与threading.Thread实现有返回值的子类MyThread

 

import threading
class MyThread(threading.Thread):
    def __init__(self,func,args=()):
        super(MyThread,self).__init__()
        self.func = func
        self.args = args
    def run(self):
        self.res = self.func(*self.args)
    def getResult(self):
        try:
            return self.res  
        except Exception:
            return None

欢迎进(Q)群,帮你解决问题:

python继承threading.Thread实现有返回值的子类_第1张图片

 

你可能感兴趣的:(python,python爬虫)