zoukankan      html  css  js  c++  java
  • Python3 多线程例子

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

      

  • 相关阅读:
    Redis
    Ajax和JSON
    快速幂
    欧拉函数
    约数
    质数
    二分图相关算法模板
    最小生成树模板
    最短路算法模板
    康托展开和逆康托展开
  • 原文地址:https://www.cnblogs.com/zhangwei22/p/10222919.html
Copyright © 2011-2022 走看看