MCPcopy Index your code
hub / github.com/pytorch/pytorch / _GetFreeFlaskPort

Function _GetFreeFlaskPort

caffe2/python/workspace.py:106–122  ·  view source on GitHub ↗

Get a free flask port.

()

Source from the content-addressed store, hash-verified

104
105
106def _GetFreeFlaskPort():
107 """Get a free flask port."""
108 # We will prefer to use 5000. If not, we will then pick a random port.
109 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
110 result = sock.connect_ex(('127.0.0.1', 5000))
111 if result == 0:
112 return 5000
113 else:
114 s = socket.socket()
115 s.bind(('', 0))
116 port = s.getsockname()[1]
117 s.close()
118 # Race condition: between the interval we close the socket and actually
119 # start a mint process, another process might have occupied the port. We
120 # don't do much here as this is mostly for convenience in research
121 # rather than 24x7 service.
122 return port
123
124def StartMint(root_folder=None, port=None):
125 """Start a mint instance.

Callers 1

StartMintFunction · 0.85

Calls 2

bindMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…