码迷,mamicode.com
首页 > 其他好文 > 详细

Thread的其他属性方法

时间:2018-06-01 17:32:16      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:read   其他   isa   __name__   isp   one   audio   isalive   class   

from threading import Thread,currentThread,active_count
import time

def task():
    print(‘%s is running‘ % currentThread().getName())
    time.sleep(2)
    print(‘%s is end‘%currentThread().getName())

if __name__ == ‘__main__‘:
    t = Thread(target=task,name = ‘子线程1‘)  #可以用name定义线程名字
    t.start()
    t.join()
    t.setName(‘儿子线程1‘)   #可以更改线程名字
    currentThread().setName(‘zhu‘)  #更改主线程名字
    print(t.isAlive())
    print(‘zhu‘,currentThread().getName())

    print(active_count())   #活跃线程数量

 

Thread的其他属性方法

标签:read   其他   isa   __name__   isp   one   audio   isalive   class   

原文地址:https://www.cnblogs.com/yelublue/p/9122545.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!