MCPcopy Create free account
hub / github.com/catboost/catboost / _get_port

Method _get_port

library/python/port_manager/__init__.py:150–173  ·  view source on GitHub ↗
(self, port, sock_type)

Source from the content-addressed store, hash-verified

148 return res
149
150 def _get_port(self, port, sock_type):
151 if port and self._no_random_ports():
152 return port
153
154 if len(self._filelocks) >= self._valid_port_count:
155 raise PortManagerException("All valid ports are taken ({}): {}".format(self._valid_range, self._filelocks))
156
157 salt = random.randint(0, UI16MAXVAL)
158 for attempt in six.moves.range(self._valid_port_count):
159 probe_port = (salt + attempt) % self._valid_port_count
160
161 for left, right in self._valid_range:
162 if probe_port >= (right - left):
163 probe_port -= right - left
164 else:
165 probe_port += left
166 break
167 if not self._capture_port(probe_port, sock_type):
168 continue
169 return probe_port
170
171 raise PortManagerException(
172 "Failed to find valid port (range: {} used: {})".format(self._valid_range, self._filelocks)
173 )
174
175 def _capture_port(self, port, sock_type):
176 with self._lock:

Callers 2

get_tcp_portMethod · 0.95
get_udp_portMethod · 0.95

Calls 6

_no_random_portsMethod · 0.95
_capture_portMethod · 0.95
lenFunction · 0.85
formatMethod · 0.45
rangeMethod · 0.45

Tested by

no test coverage detected