Accepting multiple clients in python socket server
<p>I'm trying to build a simple socket server in python:</p>

<pre><code>import socket
import threading
import time


def handle(conn_addr):
  print("Someone Connected")
  time.sleep(4)
  print("And now I die")


host = ''
port = 5000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
  s.bind((host,port))
except socket.error as e:
  print(str(e))

s.listen(2)

while True:
  threading.Thread(handle(s.accept())).start()


print("Should never be reached")
</code></pre>

<p>The socket server should accept multiple clients at the same time. I tried to test its functionality by calling telnet localhost 5000 from multiple tabs from my shell however the pattern that i get is </p>

<pre><code>Someone Connected
And now I die
Someone Connected
And now I die
</code></pre>

<p>Instead of </p>

<pre><code>Someone Connected
Someone Connected
Someone Connected
</code></pre>

<p>I call the telnet command within 4 seconds of each other so it should have 2 messages of connected in a row however the message is only returned after the previous socket is disconnected. Why is that and how could I go round fixing this?</p>