title: How to use same port twice in Python
body: <p>Even with the REUSEADDR option, I still cannot reuse the same set of ports. It gives me a 98, "address already in use" error.</p>
  
  <p>Is there a way to kill the first group of sockets before the second group, or fix this?</p>
  
  <p>In the code below, I'm doing the exact same thing twice.</p>
  
  <pre><code>servers = []
  port_list = [i for i in range(40007, 40107)]
  for port in port_list:
      ds = ('', port)
      server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
      server.bind(ds)
      server.listen(1)
      servers.append(server)
  
  found,_,_ = select.select(servers, [], [])
  found = found[0]
  conn, addr = found.accept()
  print 'Connected by', addr
  data = conn.recv(1024)
  print "received", data
  conn.sendall("message!!")
  
  conn.close()
  
  
  
  #time.sleep(10) # even this doesn't work
  
  
  port_list = [i for i in range(40007, 40107)]
  for port in port_list:
      ds = ('', port)
      server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
      server.bind(ds)
      server.listen(1)
      servers.append(server)
  
  found,_,_ = select.select(servers, [], [])
  found = found[0]
  conn, addr = found.accept()
  print 'Connected by', addr
  
  data = conn.recv(1024)
  print "received", data
  conn.sendall("message!!")
  </code></pre>