• 多线程-入门实例


    #导入模块import threading
    
    def run(n):
        print("task",n)
    #创建线程实例
    t1 = threading.Thread(target=run,args=("t1",))
    t2 = threading.Thread(target=run,args=("t2",))
    #启动线程
    t1.start()
    t2.start()
    

     多线程并行运行的

    #启动多个线程实例并行:

    import threading
    import time
    def run(n):
        print("task",n)
        time.sleep(2)
    for i in range(50):
        t1 = threading.Thread(target=run,args=("t-%s"%i,))
        t2 = threading.Thread(target=run,args=("t2-%s"%i,))
        t1.start()
        t2.start()
    
  • 相关阅读:
    团队题目及相关介绍
    团队介绍
    寒假8
    寒假作业七
    寒假7
    寒假作业六
    寒假6
    寒假作业五
    寒假5
    寒假作四
  • 原文地址:https://www.cnblogs.com/fuyuteng/p/9187279.html
Copyright © 2020-2023  润新知