午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python多線程實(shí)現(xiàn)同時(shí)執(zhí)行兩個(gè)while循環(huán)的操作

瀏覽:131日期:2022-07-26 16:43:19

如果想同時(shí)執(zhí)行兩個(gè)while True循環(huán),可以使用多線程threading來(lái)實(shí)現(xiàn)。

完整代碼

#coding=gbkfrom time import sleep, ctime import threadingdef muisc(func): while True: print ’Start playing: %s! %s’ %(func,ctime()) sleep(2) def move(func): while True: print ’Start playing: %s! %s’ %(func,ctime()) sleep(5)def player(name): r = name.split(’.’)[1] if r == ’mp3’: muisc(name) else: if r == ’mp4’: move(name) else: print ’error: The format is not recognized!’list = [’愛情買賣.mp3’,’阿凡達(dá).mp4’]threads = []files = range(len(list))#創(chuàng)建線程for i in files: t = threading.Thread(target=player,args=(list[i],)) threads.append(t)if __name__ == ’__main__’: #啟動(dòng)線程 for i in files: threads[i].start() for i in files: threads[i].join() #主線程 print ’end:%s’ %ctime()

效果:

python多線程實(shí)現(xiàn)同時(shí)執(zhí)行兩個(gè)while循環(huán)的操作

補(bǔ)充知識(shí):python 如何在一個(gè)for循環(huán)中遍歷兩個(gè)列表

利用python自帶的zip函數(shù)可同時(shí)對(duì)兩個(gè)列表進(jìn)行遍歷,代碼如下:

>>> list1 = [’a’, ’b’, ’c’, ’d’]>>> list2 = [’apple’, ’boy’, ’cat’, ’dog’]>>> for x, y in zip(list1, list2): print(x, ’is’, y)# 輸出a is appleb is boyc is catd is dog

以上這篇python多線程實(shí)現(xiàn)同時(shí)執(zhí)行兩個(gè)while循環(huán)的操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 欧美日韩视频网站 | 国产性生活网站 | 亚洲www在线 | 精品福利一区二区 | 91精品久久久久久粉嫩 | 91天堂在线| 亚洲午夜精品久久久 | 欧美色图另类图片 | 欧美性喷潮 | 日韩成人精品视频 | 毛片网站免费观看 | 色啪影院| 日韩色网 | 国产91页 | 韩日在线 | 夜色综合 | 黄色三级av | 69堂精品| 欧美色拍| 五月婷婷六月丁香综合 | a久久久久久 | 中文字幕免费高清 | 成年人在线免费观看视频网站 | 免费成人深夜夜行网站 | 亚洲图片一区 | 亚洲激情一区二区三区 | 黄色99| 久久99精品视频 | 午夜剧场伦理 | 黄色av网址大全 | 中文字幕1区2区 | 欧美亚洲视频 | 天天天天天天天操 | 激情六月丁香 | 蜜桃成人在线视频 | 日本aⅴ在线 | 91精品国产欧美一区二区 | 国产精品二区在线 | 成人一二区 | 自拍在线观看 | 爱爱网入口|