多处理池工作程序中的线程标识符 [英] Thread identifier in multiprocessing pool workers

查看:63
本文介绍了多处理池工作程序中的线程标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信Thread.ident是线程的唯一标识符,但是现在我看到multiprocessing.poo.Pool中的不同工作进程报告了threading.current_thread().ident相同的线程标识符.怎么样?

I believed Thread.ident as a unique identifier of threads but now I see different worker processes in multiprocessing.poo.Pool reporting same thread identifier by threading.current_thread().ident. How?

推荐答案

根据平台的不同,这些ID可能是唯一的,也可能不是唯一的.这里要注意的重要一点是python多重处理库实际上使用进程而不是线程进行多重处理,因此进程之间的线程id实际上是特定于平台的实现细节.

Depending on the platform, the ids may or may not be unique. The important thing to note here is that the python multiprocessing library actually uses processes instead of threads for multiprocessing, and so thread ids in between processes is actually a platform-specific implementation detail.

在Unix/Linux上:保证线程ID在单个进程内唯一.但是,不能保证线程ID在进程之间是唯一的.但是,processid(pid)在各个进程之间将是唯一的.因此,您可以通过将两者放在一起获得唯一的标识符. man pthread页面上的详细信息 http://man7.org/linux/man-pages/man7/pthreads.7.html

On Unix/Linux: a thread id is guaranteed to be unique inside a single process. However, a thread id is not guaranteed to be unique across processes. The processid (pid), however, will be unique across processes. Thus, you can obtain a unique identifier by putting the two together. Detail from the man pthread page http://man7.org/linux/man-pages/man7/pthreads.7.html

在Windows上:线程ID在整个计算机上是唯一的:

On windows: a thread id is unique across the whole machine: https://msdn.microsoft.com/en-us/library/windows/desktop/ms686746(v=vs.85).aspx

这篇关于多处理池工作程序中的线程标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆