码迷,mamicode.com
首页 > 编程语言 > 详细

线程初偿

时间:2018-04-21 13:28:36      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:utf-8   read   active   target   ==   []   count   活跃   主线程   

# -*- coding:utf-8 -*- 
# Author:Brownyangyang
import threading
import time

def sayhi(num):
print("running on number:%s" %num,threading.current_thread(),threading.active_count()) ##打印线程
#threading.current_thread() 当前县称号
#threading.active_count() 活跃线程个数
time.sleep(2)

#if __name__ == ‘__main__‘:

start_time=time.time()

item_liyan = []
for i in range(50):
t = threading.Thread(target=sayhi,args=(i,))

t.start()
#t2.start()
item_liyan.append(t)

for j in item_liyan:
j.join()


print("time %s",time.time()-start_time)
print(threading.current_thread()) ##打印主线程

#print(t1.getName())
#print(t2.getName())

线程初偿

标签:utf-8   read   active   target   ==   []   count   活跃   主线程   

原文地址:https://www.cnblogs.com/brownyangyang/p/8900668.html

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