-
-
Save kgriffs/74885ea0fdf5ccec0e3167be82ae732d to your computer and use it in GitHub Desktop.
Get Unused Port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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