多线程

作者: 八月欢喜 | 来源:发表于2020-10-23 10:15 被阅读0次

    1.多线程线程池

    threadpool 安装

    pip install threadpool

    from twisted.python.threadpool import ThreadPool
    import threadpool
    pool = ThreadPool(poolsize) # poolsize 线程大小
    requests = threadpool.makeRequests(some_callable, list_of_args, callback)
    # some_callable 多线程调用的方法 
    # list_of_args 列表数据参数
    # callback 回调函数,一般不用,可忽略
    [pool.putRequest(req) for req in requests]
    pool.wait()
    # 等待所有线程完成工作后推出
    

    相关文章

      网友评论

          本文标题:多线程

          本文链接:https://www.haomeiwen.com/subject/ieammktx.html