import threading,time
from tools.listOperation import *


class MyThread(threading.Thread):
    def __init__(self,func,divlist,**kwargs):
        super(MyThread,self).__init__()
        self.func=func
        self.divlist=divlist
        self.result=None
        self.kv=kwargs

    def run(self):
        #time.sleep(1)
        #print(threading.currentThread().name)
        #print('请求参数：',self.kv,self.divlist,self.func)
        if self.kv:
            t=self.func(self.divlist,self.kv)
        else:
            t=self.func(self.divlist)
        #print('结果:',t)
        self.result=t
        #print('over')

    def get_result(self):
        #print(self.name,'-->multhread:',self.result)
        return self.result



def main(thnum):
    num=list(range(100))
    #thnum=5
    divnum=int(len(num)/thnum)
    divlists=split_by_length(num,divnum)
    #print(divlists)
    temp=[]
    for i in range(thnum):
        t=MyThread(func,divlists[i])
        temp.append(t)
        t.start()
    for i in temp:
        i.join()


if __name__ == '__main__':
     t=time.time()
     main(5)
     tt=time.time()
     print(tt-t)
     # print("=="*50)
     # t=time.time()
     # for i in list(range(100)):
     #     print(i)
     # tt=time.time()
     # print(tt-t)







