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

线程的唯一标记

时间:2018-05-26 11:46:15      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:pre   _id   thread   span   local   ide   rgs   tar   target   

threading.local

作用:为每个线程开辟一块空间进行数据存储

线程的唯一标记get_ident

from threading import Thread
from threading import get_ident


def task(arg):
    print(get_ident())    #打印出来的是每一个线程的线程号


for i in range(10):
    t=Thread(target=task,args=(i,))
    t.start()

 

线程的唯一标记

标签:pre   _id   thread   span   local   ide   rgs   tar   target   

原文地址:https://www.cnblogs.com/dwenwen/p/9092114.html

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