def find_open_port():
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.bind(('', 0))
 port = s.getsockname()[1]
 s.close()
 return port

def find_open_port ( ) : s = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) s . bind ( ( '' , 0 ) ) port = s . getsockname ( ) [ 1 ] s . close ( ) return port
ask the os for an open port .