码迷,mamicode.com
首页 > 编程语言 > 详细

python 多进程

时间:2018-12-02 22:40:25      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:pen   image   多进程   def   round   技术分享   idt   width   进程   

from time import ctime,sleep,time
import multiprocessing
def super_play(file_, t):
    for i in range(2):
        print("Start playding: %s! %s"% (file_,ctime()))
        sleep(t)
lists={"天边.mp3":3,"廊桥遗梦.rmvb":5,"壮志凌云。avi":4}
lists_len = range(len(lists))
threads = []
for file,t in lists.items():
    p = multiprocessing.Process(target=super_play,args=(file,t))
    threads.append(p)
if __name__=="__main__":
    start = time()
    for i in lists_len:
        threads[i].start()
    for i in lists_len:
        threads[i].join()
    end = time()
    ge = round((end-start),1)
    print("共耗时%s秒"%ge)

技术分享图片

参照廖雪峰和菜鸟教程,

python 多进程

标签:pen   image   多进程   def   round   技术分享   idt   width   进程   

原文地址:https://www.cnblogs.com/csj2018/p/10055324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!