Python 多线程

原文:忘了

 

 

import threading
import time




def fn1():
    print('fn1 start')
    time.sleep(2)
    print('fn1 end')
    print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
    
    
def fn2():
    print('fn2 start')
    time.sleep(4)
    print('fn2 end')
    print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
    for i in range(20):
        print(i)
        time.sleep(2)
    


# 创建线程
thread_hi = threading.Thread(target=fn1)
thread_hello = threading.Thread(target=fn2)

# 启动线程
thread_hi.start()
thread_hello.start()
print('ok')
print(print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))))

 

posted @ 2020-02-14 16:51  古兴越  阅读(104)  评论(0编辑  收藏  举报