zoukankan      html  css  js  c++  java
  • python 多进程线程之传入多参数问题

    #! /usr/bin/env python
    # -*- coding: utf-8 -*-#
    
    # -------------------------------------------------------------------------------
    # Name:         tools
    # Author:       yunhgu
    # Date:         2021/7/1 11:06
    # Description: 
    # -------------------------------------------------------------------------------
    from concurrent.futures import ProcessPoolExecutor, as_completed
    from multiprocessing import Pool
    import time
    import os
    
    
    def work(a):
        time.sleep(1)
        print(f"{a}:{os.getpid()}")
        return a
    
    
    def main():
        with ProcessPoolExecutor(max_workers=None) as p:
            task_list = []
            for i in range(3):
                for j in range(3):
                    for z in range(3):
                        a = (i, j, z)
                        task = p.submit(work, a)
                        task_list.append(task)
            for task in as_completed(task_list):
                if task.done():
                    print(task.result())
    
    
    if __name__ == '__main__':
        start_time = time.time()
        main()
        print(time.time() - start_time)
        # main2()
    
    不论你在什么时候开始,重要的是开始之后就不要停止。 不论你在什么时候结束,重要的是结束之后就不要悔恨。
  • 相关阅读:
    二十一、Mysql之GTID
    二十、Mysql的过滤复制
    十九、Mysql的半同步复制
    十八、Mysql之延时从库
    十七、Mysql的主从(三)--主从故障监控分析
    抖音爬虫
    python 操作手机
    python sheet写入数据
    pandas用法大全
    caog
  • 原文地址:https://www.cnblogs.com/yunhgu/p/14959223.html
Copyright © 2011-2022 走看看