返回顶部

收藏

Multi-threading: zip file

更多
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.'

标签:Python,File

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2015-11-27 20:36:13Iterating Over Lines with readlines by 张宋付
  2. 2016-01-04 17:35:46Closing Files by 西国の海妖
  3. 2016-08-19 15:46:08Working with Directories by 西国の海妖
  4. 2016-09-03 11:47:53Define function to Open a file by 阮小七
  5. 2016-09-19 19:25:12File Output by jack.chen
  6. 2016-10-19 10:47:50Handling I/O Errors by 大猪
  7. 2016-12-06 09:03:52Demonstrates writing to a text file by 张宋付
  8. 2016-03-26 20:56:22Reading Everything: read the whole file in one go by 风云轩
  9. 2016-08-19 15:55:27Working with File Objects by Solon.Ring
  10. 2016-09-03 14:35:51Writing to Files by 西国の海妖
  11. 2016-10-19 11:28:30Reads a single line from the file by 蟋蟀MM

发表评论