最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python 多線程實例詳解

 更新時間:2017年03月25日 16:11:52   投稿:lqh  
這篇文章主要介紹了Python 多線程實例詳解的相關(guān)資料,需要的朋友可以參考下

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

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

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

相關(guān)文章

最新評論

东阳市| 株洲县| 延川县| 芮城县| 乌鲁木齐县| 徐水县| 通许县| 温泉县| 囊谦县| 抚州市| 南川市| 日照市| 襄垣县| 衢州市| 天镇县| 黄石市| 南雄市| 垫江县| 新泰市| 内乡县| 隆子县| 乌拉特后旗| 全州县| 南京市| 油尖旺区| 江达县| 临邑县| 德令哈市| 镇康县| 芦溪县| 东乡县| 商水县| 海兴县| 泸溪县| 临漳县| 盐山县| 扶绥县| 新沂市| 大埔县| 临漳县| 静宁县|