def bind_unused_port(reuse_port=False):
 sock = netutil.bind_sockets(None, '127.0.0.1', family=socket.AF_INET, reuse_port=reuse_port)[0]
 port = sock.getsockname()[1]
 return (sock, port)

def bind_unused_port ( reuse_port = False ) : sock = netutil . bind_sockets ( None , '127.0.0.1' , family = socket . AF_INET , reuse_port = reuse_port ) [ 0 ] port = sock . getsockname ( ) [ 1 ] return ( sock , port )
binds a server socket to an available port on localhost .