python多线程压缩文件

#coding utf-8


import threading
import 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('d:my.txt','d:my.zip')
background.start()              //线程开始
print('the main program continues to run in foreground.')
background.join()        //其它线程加入


print('finish')

你可能感兴趣的:(python)