37,719
社区成员
发帖
与我相关
我的任务
分享
import threading
from time import ctime, sleep
class MyThread(threading.Thread):
def __init__(self, func, args, name=''):
threading.Thread.__init__(self)
self.name = name
self.func = func
self.args = args
def run(self):
# apply(self.func, self.args) # 用不了...
# function(self.func,self.args,self.name)
pass
def super_play(file, time):
for i in range(2):
print('开始运行: %s! %s' % (file, ctime()))
sleep(time)
list = {'爱情买卖.mp3':2, '雷神.mp4':5}
threads = []
files = range(len(list))
for k,v in list.items():
t = MyThread(super_play,(k,v),super_play.__name__)
threads.append(t)
if __name__ == '__main__':
for i in files:
threads[i].start()
for i in files:
threads[i].join()
print('结束 %s' % ctime())
def run(self):
self.func(*self.args)
pass