December 2018
Intermediate to advanced
374 pages
11h 39m
English
As we saw in the previous section, we do not need an infinite number of threads to handle the incoming clients. We can manage with a limited number of threads to handle a large number of clients. But, how do we implement this thread pooling in our application. As it turns out, it is quite easy to implement the thread pool functionality with Python 3 and the concurrent.futures module.
The following code sample modifies our existing TCP server example to use a thread pool, instead of arbitrarily launching an infinite number of threads to handle the incoming client connections:
# simple_socket_threadpool.py#!/usr/bin/python3from concurrent.futures import ThreadPoolExecutorimport socket# Let's ...
Read now
Unlock full access