未验证 提交 8fe8039e 编写于 作者: K kuizhiqing 提交者: GitHub

Launch fix port (#40936)

上级 27996fd1
......@@ -25,6 +25,7 @@ class Node(object):
self.device = Device.parse_device()
self.ip = self.get_host_ip()
self.free_ports = []
self._allocated_ports = []
def get_host_ip(self):
try:
......@@ -42,13 +43,18 @@ class Node(object):
def get_ports_occupied(self):
return self.free_ports
@classmethod
def get_free_port(self):
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
struct.pack('ii', 1, 0))
s.bind(('', 0))
return s.getsockname()[1]
for _ in range(100):
with closing(socket.socket(socket.AF_INET,
socket.SOCK_STREAM)) as s:
s.bind(('', 0))
port = s.getsockname()[1]
if port in self._allocated_ports:
continue
else:
self._allocated_ports.append(port)
return port
return port
@classmethod
def is_server_ready(self, ip, port):
......
......@@ -36,7 +36,7 @@ def launch():
Base Parameters:
- ``--master``: The master/rendezvous server, support http:// and etcd://, default with http://. e.g., ``--master=127.0.0.1:8080``. Default ``--log_dir=None``.
- ``--master``: The master/rendezvous server, support http:// and etcd://, default with http://. e.g., ``--master=127.0.0.1:8080``. Default ``--master=None``.
- ``--rank``: The rank of the node, can be auto assigned by master. Default ``--rank=-1``.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册