Created
January 20, 2020 22:22
-
-
Save jmvrbanac/63a6984d0837a67100ea83e4c7b22d63 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