MCPcopy Create free account
hub / github.com/SooLab/CGFormer / find_free_port

Function find_free_port

utils/misc.py:200–208  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

198
199
200def find_free_port():
201 import socket
202 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
203 # Binding to port 0 will cause the OS to find an available port for us
204 sock.bind(("", 0))
205 port = sock.getsockname()[1]
206 sock.close()
207 # NOTE: there is still a chance the port could be taken by other processes.
208 return port
209
210
211def get_caller_name(depth=0):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected