python之线程2(单线程和多线程)
python之線程2(單線程和多線程)
# -*- coding: UTF-8 -*-import threadingfrom time import ctime, sleepclass MyThread(threading.Thread): def __init__(self, func, args, name=''): threading.Thread.__init__(self) self.name = name self.func = func self.args = args def getResult(self): return self.res def run(self): print 'starting', self.name, 'at:', ctime() self.res = self.func(*self.args) print self.name, 'finished at:', ctime()# -*- coding: UTF-8 -*-from myThread import MyThreadfrom time import ctime, sleep#threading模塊的其他函數(shù)#activeCount/active_count(): 當(dāng)前活動(dòng)的Thread對(duì)象個(gè)數(shù)#currentThread()/current_thread: 返回當(dāng)前的Thread對(duì)象#enumerate(): 放回當(dāng)前活動(dòng)的Thread對(duì)象列表#settrace(func),為所有線程設(shè)置一個(gè)trace函數(shù)#setprofile(func), 為所有線程設(shè)置一個(gè)profile函數(shù)#stack_size(size=0), 返回新創(chuàng)建線程的棧大小,或?yàn)楹罄m(xù)創(chuàng)建的線程設(shè)定棧的大小為size#斐波那契