1. 程式人生 > >Python--多執行緒學習(11.3)

Python--多執行緒學習(11.3)

上Code

#多執行緒應用

import _thread
import time

def print_time( threadName,delay):
    count = 0
    while count < 5:
        time.sleep(delay)  #unit :毫秒
        count += 1
        print("%s %s"%(threadName,time.ctime(time.time())))

try:
    _thread.start_new_thread(print_time,("Thread-1",2,))  #arg1:執行函式  arg2:函式對應引數
    _thread.start_new_thread(print_time,("Thread-2",8,))
except:
    print("error")

while 1:
    pass