Q:

New client right after accept function call

Suppose that I have the following code:
import socket

listener = socket.socket()
listener.bind(('0.0.0.0', 59535))
while True:
    conn, addr = listener.accept()
    worker_thread = threading.Thread(target=client_handler, args=(conn, addr,)).start()

What will happen if new client will try to connect to our listener socket while we're creating worker thread? Will he wait for the next accept call or will it just rejected? If he'll wait, how many clients can be in that queue simultaneously by default (yeah, I know that I can set it via listen function)?

A:

There is a listen queue in the kernel, so the kernel will deal with new clients while your user space part does something else. If the listen queue in the kernel is full no more clients will be accepted, that is the connect will fail.

