Skip to content Skip to sidebar Skip to footer

Thread Identifier In Multiprocessing Pool Workers

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

Solution 1:

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.

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

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

Post a Comment for "Thread Identifier In Multiprocessing Pool Workers"