How to obtain a Thread id in Python?

后端 未结 8 827
时光说笑
时光说笑 2020-12-02 08:01

I have a multi-threading Python program, and a utility function, writeLog(message), that writes out a timestamp followed by the message. Unfortunately, the resu

8条回答
  •  暖寄归人
    2020-12-02 08:38

    I saw examples of thread IDs like this:

    class myThread(threading.Thread):
        def __init__(self, threadID, name, counter):
            self.threadID = threadID
            ...
    

    The threading module docs lists name attribute as well:

    ...
    
    A thread has a name. 
    The name can be passed to the constructor, 
    and read or changed through the name attribute.
    
    ...
    
    Thread.name
    
    A string used for identification purposes only. 
    It has no semantics. Multiple threads may
    be given the same name. The initial name is set by the constructor.
    

提交回复
热议问题