在Python中,可以使用threading.current_thread().name来获取当前线程的名字。

以下是一个示例:

import threading

def worker():
    print(f"当前线程名字: {threading.current_thread().name}")

if __name__ == "__main__":
    t = threading.Thread(target=worker)
    t.start()

输出示例:

当前线程名字: Thread-1
python 获取当前线程名

原文地址: https://www.cveoy.top/t/topic/hQ8p 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录