The thread pool is the concept of an operating system, which is an optimization of multithreading.
When multithreading, creating and destroying threads is associated with the overhead of the operating system, and if threads are created/destroyed frequently, the efficiency is greatly reduced.
The thread pool is the first to create a batch of threads into the pool, need to create a thread from the pool, and then put it in the pool.
Obviously, the use of the thread pool saves time for threads to be created and destroyed.
This is a space-for- time approach because the created thread is to be placed somewhere in memory.
Another benefit of using the thread pool is that it limits the number of threads.
How many threads in the thread pool can be specified manually.
Joining does not use a thread pool, so if you create a lot of threads at once, scheduling between threads can waste a lot of time.
The thread pool limits the number of threads in multithreaded situations, and improves execution efficiency by reducing multi-threading.
In Python, because there is a Gil(Global interpreter Lock) lock, the Gil Lock is first obtained before any Python thread executes.
Each execution of 100 bytecode, the interpreter automatically releases the Gil lock, so that other threads have the opportunity to execute on the same CPU.
So on the surface, because of the Gil's existence, the multithreading in Python seems to have little effect.
It's actually a bit of a function, for IO-intensive tasks, when a long wait time is required, the Gil is conceded so that other threads can get
Gil and run.
The thread pool and the Gil in Python