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()))))
原文地址:https://www.cnblogs.com/guxingy/p/12307995.html