提交 10d9d77e 编写于 作者: M Megvii Engine Team

refactor(mge/distributed): remove get_free_ports func

GitOrigin-RevId: b85c4885be74f3135c6707831dedf31b51356e8f
上级 0adf49b1
......@@ -22,4 +22,3 @@ from .group import (
from .helper import bcast_list_, make_allreduce_cb, synchronized
from .launcher import launcher
from .server import Client, Server
from .util import get_free_ports
......@@ -13,7 +13,6 @@ from ..core._imperative_rt.core2 import sync
from .group import group_barrier, init_process_group
from .helper import get_device_count_by_fork
from .server import Client, Server
from .util import get_free_ports
def _run_wrapped(
......
......@@ -17,7 +17,6 @@ from xmlrpc.server import SimpleXMLRPCServer
from ..core._imperative_rt.utils import create_mm_server
from ..utils.future import Future
from .util import get_free_ports
class Methods:
......
# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
# Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import functools
import socket
from typing import List
def get_free_ports(num: int) -> List[int]:
"""
Get one or more free ports.
"""
socks, ports = [], []
for i in range(num):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("", 0))
socks.append(sock)
ports.append(sock.getsockname()[1])
for sock in socks:
sock.close()
return ports
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册