在 PyDev 调试视图中命名线程

发布于 2024-12-23 12:14:38 字数 146 浏览 1 评论 0原文

PyDev 的调试视图显示了线程,但它们的名称很神秘:

Cryptic thread names

有没有办法从内部命名这些线程python代码?

PyDev's debug view shows the threads, however their names are cryptic:

Cryptic thread names

Is there a way to name these threads from within the python code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紅太極 2024-12-30 12:14:38

看起来 PyDev 中显示的名称是默认分配的名称。

要解决此问题,您可以在创建线程时为其指定名称:

threading.Thread(name=<name>, target=...)

或者稍后只需设置 name 属性即可:

thread = threading.Thread(*args, **kwargs)
thread.name = <name>

It looks like the names being displayed in PyDev are the ones assigned by default.

To fix that you can give a name to the thread when it's created:

threading.Thread(name=<name>, target=...)

or, later, just by setting the name attribute:

thread = threading.Thread(*args, **kwargs)
thread.name = <name>
若无相欠,怎会相见 2024-12-30 12:14:38

尝试使用 getName/setName API 或设置 name 线程上的属性。或者您可以在创建线程时设置名称。

Try using the getName/setName API or setting name attribute on a thread. Or you can set name when the thread is created.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文