Skip to content

Instantly share code, notes, and snippets.

@jmvrbanac
Created January 20, 2020 22:22
Show Gist options
  • Save jmvrbanac/63a6984d0837a67100ea83e4c7b22d63 to your computer and use it in GitHub Desktop.
Save jmvrbanac/63a6984d0837a67100ea83e4c7b22d63 to your computer and use it in GitHub Desktop.
Get Unused Port
def get_unused_port():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 0))
_, port = sock.getsockname()
sock.close()
return port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment