zoukankan      html  css  js  c++  java
  • 进程池与线程池

    #进程池
    from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor
    import time,os
    pool=ProcessPoolExecutor(5)
    def task(n):
        print(n,os.getpid())
        time.sleep(2)
        return n*n
    
    def call_back(n):
        print('call_back>>:',n.result())
    
    if __name__ == '__main__':
        for i in range(10):
            res=pool.submit(task,i).add_done_callback(call_back)
    #线程池
    from concurrent.futures import ThreadPoolExecutor
    import os,time
    t=ThreadPoolExecutor(5)
    def task(n):
        print(n,os.getpid())
        time.sleep(2)
        return n
    
    def call_back(n):
        print('call_back:',n.result())
    
    if __name__ == '__main__':
        for i in range(10):
            res=t.submit(task,i).add_done_callback(call_back)
    
  • 相关阅读:
    PG
    unzip
    yum
    PG
    SQL
    Grails
    Grails
    Grails
    Chrome
    HTML
  • 原文地址:https://www.cnblogs.com/linqiaobao/p/12789894.html
Copyright © 2011-2022 走看看