python3+selenium多线程

· 创建线程函数

· 创建要传入的args参数

· for循环创建线程 

from time import sleep, ctime
import threading


# 创建超级播放器
def super_player(file_, loop):
    for i in range(2):
        print('start playing: %s !%s' % (file_, ctime()))
        sleep(2)
# 播放文件与播放时长
lists = {'爱情买卖.mp3':3,'阿凡达.mp4':5,'传奇.mp3':4}

threads = []
files = range(len(lists))
print(files)
# 创建线程
print(lists.items())
for file_,time in lists.items():
    t = threading.Thread(target=super_player,args=(file_,time))
    print(t)
    threads.append(t)

if __name__ == '__main__':
    # 启动线程
    for t in files:
        threads[t].start()
    # 守护线程
    for t in files:
        threads[t].join()

    print(' end:%s'% ctime())
发布了52 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/yijinaqingan/article/details/87860402