首页 > 其他 > 详细

threading Tread属性

时间:2019-02-23 23:52:44      阅读:251      评论:0      收藏:0      [点我收藏+]
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))

threading Tread属性

原文:https://blog.51cto.com/windchasereric/2353992

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!