Thread对象的属性
import threading
from time import sleep,ctime
def pri(py,n):
name=p1.name # 线程名
id=p1.ident # 线程标识符
for i in range(n):
print('name=%s now=%s id=%s'%(name,ctime(),id))
sleep(1)
p1=threading.Thread(target=pri,args=('python',3),name='chian')
#p1.setName('chinese') # 设置线程名
p1.start() # 启动线程
args参数类型为元组,所以只有一个参数时为(‘python’,)

join()的使用比较
import threading
from time import sleep,ctime
def pri():
for i in range(3):
print('pri1=%s'%ctime())
sleep(1)
p1=threading.Thread(target=pri,daemon=True)
p1.start()
p1.join() # 使主线程挂起
print("___end")
print(threading.activeCount())


博客介绍了Python中Thread对象的属性,指出args参数类型为元组,若只有一个参数需写成(‘python’,)的形式,还提及了join()的使用情况。
1803

被折叠的 条评论
为什么被折叠?



