Is there a differnce between ThreadPoolExecutor
from concurrent.futures
and ThreadPool
from multiprocessing.dummy
?
This article suggests that ThreadPool
queries the "threads" (task) to the different "threads" of the CPU. Does concurrent.futures
do the same or will the "threads" (tasks) query to a single "thread" of a CPU?
Asked
Active
Viewed 391 times
1
-
"This article suggests that ThreadPool queries the "threads" (task) to the different "threads" of the CPU" - does it? I've skimmed the article and couldn't find that claim. Anyway, in Python, threads always run on the same CPU thread (because of GIL), while processes can run on multiple CPU cores. – ForceBru Mar 14 '21 at 13:44
-
@ForceBru this is a very surface understanding of GIL in Python. Python uses standard OS threads, just uses Lock to prevent simultanious execution and protect virtual machine state. But for IO and syscalls Python releases Lock, also libraries could release the GIL on C-level even for CPU-bound tasks. So, the threads run on those cores, which OS Scheduler decide, but usually they execute sequentially. – NobbyNobbs Mar 14 '21 at 14:17
-
Does this answer your question? [Concurrent.futures vs Multiprocessing in Python 3](https://stackoverflow.com/questions/20776189/concurrent-futures-vs-multiprocessing-in-python-3) – NobbyNobbs Mar 14 '21 at 14:38
-
1@NobbyNobbs: The answer you posted compare multiprocessing and threads. In my understanding apply multiprocessing.dummy the functions from multiprocessing on threads. My question is more or less if is it possible to query threads to diffrent cores or threads of a cpu or not? But very intressting article. thx :) – maximilian machiavelli Mar 14 '21 at 16:48