If we are working with Python version 3.4+, there is a module called selectors, which provides an API for quickly building an object-oriented server based on the I/O primitives. The documentation and an example of this is available at https://docs.python.org/3.7/library/selectors.html.
In this example, we are going to implement a server that controls several connections using the selectors package.
You can find the following code in the tcp_server_selectors.py file:
#!/usr/bin/env python3import selectorsimport typesimport socketselector = selectors.DefaultSelector()def accept_connection(sock): connection, address = sock.accept() print('Connection accepted in {}'.format(address)) # We put the ...