1 run()方法
1.1 单个线程
在threading.Thread()类中有run()方法。
from time import ctime,sleep import threading # 定义自己类的功能 class MyThread(threading.Thread): def __init__(self,func,args,name = ""): threading.Thread.__init__(self) self.func = func self.args = args self.name = name # 调用start自动执行的函数 def run(self): self.func(*self.args) def player(song_file,time): for i in range(2): print("start player %s . %s"%(song_file,ctime()) ) sleep(time) threads = [] t = MyThread(player,('You and me .mp3',4),'Ipod') threads.append(t) t.start() t.join()