def random_port():
 sock = socket.socket()
 sock.bind(('', 0))
 port = sock.getsockname()[1]
 sock.close()
 return port

def random_port ( ) : sock = socket . socket ( ) sock . bind ( ( '' , 0 ) ) port = sock . getsockname ( ) [ 1 ] sock . close ( ) return port
get a random free port .