def find_available_local_port():
infos = socket.getaddrinfo(None, <NUM_LIT:0>, socket.AF_UNSPEC, socket.SOCK_STREAM)<EOL>family, proto, _, _, addr = next(iter(infos))<EOL>sock = socket.socket(family, proto)<EOL>sock.bind(addr)<EOL>addr, port = sock.getsockname()[:<NUM_LIT:2>]<EOL>sock.close()<EOL>return port<EOL>
Find a free port on localhost.

>>> 0 < find_available_local_port() < 65536
True