Skip to content

Instantly share code, notes, and snippets.

@xinzhel
Created May 29, 2022 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xinzhel/139854e3e002f05084c3bd0e062128b3 to your computer and use it in GitHub Desktop.
Save xinzhel/139854e3e002f05084c3bd0e062128b3 to your computer and use it in GitHub Desktop.
Finding an Available Port
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
 sock.bind(("", 0)
 primary_port = sock.getsockname()[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment