美文网首页
循环线程

循环线程

作者: _王子_ | 来源:发表于2018-06-04 19:05 被阅读0次
    引入   import threading模块
    ……
    if __name__ == "__main__":
    
    # 创建数组存放线程
    threads = []
    # 创建10个线程
    for i in range (10):
        # 针对函数创建线程
    
        t = threading.Thread (target=test_func, args=())
        # 把创建的线程加入线程组
        threads.append (t)
    
    # 启动线程(记法一)
    # for t in threads:
    #     t.setDaemon (True)
    #     t.start ()
    #     t.join ()
    # 启动线程(记法二)
    for i in threads:
        i.start ()
        # keep thread
    for i in threads:
        i.join ()

    相关文章

      网友评论

          本文标题:循环线程

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