zoukankan      html  css  js  c++  java
  • threading线程进程

    
    
    import threading
    import time
    
    def foo(n):
        print("foo......%s"%n)
        time.sleep(2) #两个线程是同时执行的,执行结束后再执行aaaaa
        print("aaaaa")
    
    def bar(m):
        print("bar......%s"%m)
        time.sleep(5)   #两个线程是同时执行的,执行结束后再执行bbbbb
        print("bbbbb")
    
    #创建线程,
    t1 = threading.Thread(target=foo,args=(1,)) #foo是对象
    t2 = threading.Thread(target=bar,args=(2,)) #args是参数
    
    t1.start()  #两个线程同时执行
    t2.start()
    #线程是操作系统里能运算的最小单位
    
    
    
    import threading
    import time
    
    def foo(n):
        print("foo......%s"%n)
        time.sleep(2) #两个线程是同时执行的,执行结束后再执行aaaaa
        print("aaaaa")
    
    def bar(m):
        print("bar......%s"%m)
        time.sleep(5)   #两个线程是同时执行的,执行结束后再执行bbbbb
        print("bbbbb")
    
    #创建线程,
    t1 = threading.Thread(target=foo,args=(1,)) #foo是对象
    t2 = threading.Thread(target=bar,args=(2,)) #args是参数
    
    t1.start()  #两个线程同时执行
    t2.start()
    
    t1.join()   #这个是t1,t2线程执行结束后才执行后面的内容
    t2.join()
    print("-------mind in china-------")
    #线程是操作系统里能运算的最小单位
     
  • 相关阅读:
    代码模板
    DNSget Ip
    WC约束示使用
    下雨了
    Xml文件保存值不能及时更新
    代码不是艺术,而是达到目的的一种手段
    网站TCP链接暴增
    吐个槽吧
    正则表达式使用小注意
    Sereja and Two Sequences CodeForces
  • 原文地址:https://www.cnblogs.com/TKOPython/p/12430626.html
Copyright © 2011-2022 走看看