threading Tread屬性

name,ident,is_active參數的演示

import threading
import time

def worker():
    count = 0
    while True:
        if count > 5:
            break
        time.sleep(2)
        count += 1
        print(threading.current_thread().name)

t = threading.Thread(target=worker, name="worker")
print(t.ident)
t.start()

while True:
    time.sleep(1)
    if t.is_alive():
        print('{} {} alive'.format(t.name, t.ident))
    else:
        print('{} {} dead'.format(t.name, t.ident))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章