title: Handle multiple simultaneous SFTP connections
body: <p>I'm implementing a SFTP server, using <a href="https://github.com/rspivak/sftpserver" rel="nofollow">https://github.com/rspivak/sftpserver</a> as reference. The reason for rolling out my own solution is a custom authentication scheme and special chrooting and black/whitelisting criterias.</p>
  
  <p>My problem now is handling multiple connections at once. My current loop looks like this:</p>
  
  <pre><code># Wait for a connection
  conn, addr = server_socket.accept()
  
  # Open a transport for this connection
  tr = Transport(conn)
  
  # Load our private host key
  key = RSAKey.from_private_key_file("sftp.key")
  tr.add_server_key(key)
  
  # Tell server to support SFTP
  tr.set_subsystem_handler("sftp", SFTPServer, sftp.ChrootedSFTP)
  
  # Start a SSH server for this connection and serv it
  server = auth.ChrootedAuthServer(db_factory, "/path/to/chroot")
  tr.start_server(server=server)
  
  # Wait for client to establish SSH connection
  ch = tr.accept()
  </code></pre>
  
  <p>My solution doesn't have to be blazing fast. Just able to handle about 10 simultaneous connections, each pushing data every once in a while. How do I accomplish this?</p>