日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

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

系統(tǒng) 1926 0

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

多線程通常是新開(kāi)一個(gè)后臺(tái)線程去處理比較耗時(shí)的操作,Python做后臺(tái)線程處理也是很簡(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ì)本站的支持!


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 呼和浩特市| 麟游县| 徐闻县| 建水县| 普陀区| 洛阳市| 溆浦县| 微博| 榆林市| 融水| 巴青县| 泌阳县| 文成县| 油尖旺区| 福海县| 潼南县| 高密市| 前郭尔| 陇川县| 嫩江县| 潞西市| 铜山县| 广汉市| 台湾省| 博客| 陈巴尔虎旗| 台南市| 大埔区| 日土县| 葵青区| 洮南市| 肥城市| 翁源县| 仁化县| 芦溪县| 西乌珠穆沁旗| 丰镇市| 油尖旺区| 湄潭县| 清新县| 横山县|