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(): 當前活動的Thread對象個數(shù)#currentThread()/current_thread: 返回當前的Thread對象#enumerate(): 放回當前活動的Thread對象列表#settrace(func),為所有線程設置一個trace函數(shù)#setprofile(func), 為所有線程設置一個profile函數(shù)#stack_size(size=0), 返回新創(chuàng)建線程的棧大小