Created
May 29, 2022 00:53
-
-
Save xinzhel/139854e3e002f05084c3bd0e062128b3 to your computer and use it in GitHub Desktop.
Finding an Available Port
This file contains hidden or 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
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