国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

Python 多線(xiàn)程實(shí)例詳解

2020-02-23 04:30:39
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Python 多線(xiàn)程實(shí)例詳解

多線(xiàn)程通常是新開(kāi)一個(gè)后臺(tái)線(xiàn)程去處理比較耗時(shí)的操作,Python做后臺(tái)線(xiàn)程處理也是很簡(jiǎn)單的,今天從官方文檔中找到了一個(gè)Demo.

實(shí)例代碼:

import threading, zipfile  class AsyncZip(threading.Thread):   def __init__(self, infile, outfile):     threading.Thread.__init__(self)     self.infile = infile     self.outfile = outfile   def run(self):     f = zipfile.ZipFile(self.outfile, 'w', zipfile.ZIP_DEFLATED)     f.write(self.infile)     f.close()     print('Finished background zip of:', self.infile)  background = AsyncZip('mydata.txt', 'myarchive.zip') background.start() print('The main program continues to run in foreground.')  background.join()  # Wait for the background task to finish print('Main program waited until background was done.') 

結(jié)果:

The main program continues to run in foreground. Finished background zip of: mydata.txt Main program waited until background was done. Press any key to continue . . . 

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 乌拉特后旗| 禄丰县| 白沙| 防城港市| 泗阳县| 仙桃市| 定日县| 津市市| 北宁市| 浦东新区| 富平县| 天镇县| 温州市| 含山县| 二连浩特市| 台南市| 合作市| 东莞市| 肥城市| 定襄县| 黑水县| 宝山区| 武胜县| 晋中市| 会昌县| 青河县| 濮阳市| 旺苍县| 德令哈市| 驻马店市| 砀山县| 鲜城| 莫力| 越西县| 梁山县| 社会| 马鞍山市| 扎赉特旗| 鄯善县| 布尔津县| 融水|