class MyThread(object): ''' 多线程,获取返回值 ''' def __init__(self, func_list=None): self.ret_flag = 0 self.func_list = func_list self.threads = [] def set_thread_func_list(self, func_list): self.func_list = func_list def ret_value(self): return self.ret_flag def trace_func(self, func, *args, **kwargs): ret = func(*args, **kwargs) self.ret_flag += ret def start(self): self.threads = [] self.ret_flag = 0 for func_dict in self.func_list: if func_dict["args"]: new_arg_list = [] new_arg_list.append(func_dict["func"]) for arg in func_dict["args"]: new_arg_list.append(arg) new_arg_tuple = tuple(new_arg_list) print new_arg_tuple t = threading.Thread(target=self.trace_func, args=new_arg_tuple) else: t = threading.Thread(target=self.trace_func, args=(func_dict["func"],)) self.threads.append(t) map(lambda x:x.start(),self.threads) map(lambda x:x.join(),self.threads)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。