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

首頁 > 編程 > Python > 正文

Python 多線程實例詳解

2019-11-25 16:17:16
字體:
來源:轉載
供稿:網友

Python 多線程實例詳解

多線程通常是新開一個后臺線程去處理比較耗時的操作,Python做后臺線程處理也是很簡單的,今天從官方文檔中找到了一個Demo.

實例代碼:

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.') 

結果:

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 . . . 

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 百色市| 阳原县| 海盐县| 乳山市| 阿拉尔市| 景洪市| 黄大仙区| 德州市| 都安| 河北区| 镇沅| 迭部县| 蓬莱市| 沈阳市| 铁力市| 平阳县| 湘潭县| 彭泽县| 濮阳县| 盐池县| 竹溪县| 叶城县| 九台市| 邹平县| 陆川县| 龙州县| 沅陵县| 新津县| 镇康县| 灵台县| 文山县| 红安县| 临澧县| 确山县| 合肥市| 龙里县| 介休市| 扎兰屯市| 增城市| 南平市| 莱阳市|