Python version of the one implemented in Ruby. Needed again for server testing ... prz
def unused_port():
import socket
sock = socket.socket()
sock.bind(("localhost", 0))
port = sock.getsockname()[1]
sock.close()
return port
Recommended Posts