【问题标题】:How can I get Thread ID in Python 2.4.3?如何在 Python 2.4.3 中获取线程 ID?
【发布时间】:2015-06-30 13:38:26
【问题描述】:

我有一个程序,我分别启动 3 个线程。我使用的是 2.4.3 版本。

thread.get_ident() 我猜在这个版本的 Python 中不可用。 我使用threading.currentThread(),但它只返回给我:

<_MainThread(MainThread, started)>

在其他版本 (3.3.3) 我得到类似的东西

<_MainThread(MainThread, started 5420)>

其中5420 表示线程ID。如何在 Python 2.4 版本中获取此 ID?

【问题讨论】:

标签: python multithreading process pid


【解决方案1】:

根据2.4.3 thread docs,get_ident是thread上的一个方法:

get_ident()

返回当前线程的“线程标识符”。这是一个非零整数。它的价值没有直接的意义;它旨在作为一种神奇的 cookie 来使用,例如索引线程特定数据的字典。当一个线程退出并创建另一个线程时,线程标识符可能会被回收。

【讨论】:

    猜你喜欢
    • 2010-10-29
    • 1970-01-01
    • 2011-03-18
    • 2021-11-30
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    • 2011-11-17
    • 2015-12-11
    相关资源
    最近更新 更多