【问题标题】:Is there a way to set title/name of a thread in Python? [duplicate]有没有办法在 Python 中设置线程的标题/名称? [复制]
【发布时间】:2017-06-27 15:57:13
【问题描述】:

我想在 Python 中设置一个线程的标题(在pstop 中看到的标题),以使其对处理跟踪程序可见。当使用/usr/bin/python并通过./script调用脚本时,进程的所有线程始终称为python或称为文件名。

现在,我想更改每个线程的名称。我有一个带有 4 个线程(包括主线程)的简单脚本。我使用threading 来启动线程。

有没有一种方法可以在无需安装第三方软件的情况下实现这一目标?任何指导表示赞赏。

【问题讨论】:

  • 解决了这个问题,谢谢。

标签: python multithreading linux-kernel python-multithreading


【解决方案1】:

试试这个:

def your_function(arg1, arg2, argn):
    * do stuff *


new_thread = threading.Thread(target=your_function, args=(arg1, arg2, argn))
new_thread.name = 'your name'
new.thread.start()

new_thread.name 是你的答案。

【讨论】:

【解决方案2】:

只需执行以下操作: t = threading.Thread(name='my_thread')

【讨论】:

  • 不,那没用,检查 cmets 中的链接,必须使用 pactl 才能将名称注册到 linux 进程列表。
  • 你的意思可能是this
  • 为什么上面的答案有 17 个赞,而这个有 -2?即使两个答案都没有解决实际问题
猜你喜欢
  • 2010-09-26
  • 1970-01-01
  • 2012-05-07
  • 2010-10-08
  • 1970-01-01
  • 2010-09-14
  • 1970-01-01
  • 1970-01-01
  • 2018-08-10
相关资源
最近更新 更多