def find_free_port(interface='127.0.0.1', socket_family=socket.AF_INET, socket_type=socket.SOCK_STREAM):
 address = socket.getaddrinfo(interface, 0)[0][4]
 probe = socket.socket(socket_family, socket_type)
 try:
  probe.bind(address)
  return probe.getsockname()
 finally:
  probe.close()

def find_free_port ( interface = '127.0.0.1' , socket_family = socket . AF_INET , socket_type = socket . SOCK_STREAM ) : address = socket . getaddrinfo ( interface , 0 ) [ 0 ] [ 4 ] probe = socket . socket ( socket_family , socket_type ) try : probe . bind ( address ) return probe . getsockname ( ) finally : probe . close ( )
return a host free port in the range [start_port .