线程的唯一标记

Posted dwenwen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了线程的唯一标记相关的知识,希望对你有一定的参考价值。

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()

 

以上是关于线程的唯一标记的主要内容,如果未能解决你的问题,请参考以下文章