您好,登錄后才能下訂單哦!
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)
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。