threadingTread属性

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))

网站名称:threadingTread属性
本文网址:http://csdahua.cn/article/pdhpgs.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流