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

fix(mge/distributed): fix get_free_ports return value

GitOrigin-RevId: 8a546855c43863d2cd6e96e7e9f7577811e1169d
上级 1d7fceca
......@@ -8,7 +8,7 @@
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import functools
import socket
from typing import Callable, Optional
from typing import Callable, List, Optional
import megengine._internal as mgb
......@@ -122,9 +122,8 @@ def synchronized(func: Callable):
return wrapper
def get_free_ports(num: Optional[int] = 1) -> int:
def get_free_ports(num: int) -> List[int]:
"""Get one or more free ports.
Return an integer if num is 1, otherwise return a list of integers
"""
socks, ports = [], []
for i in range(num):
......@@ -134,4 +133,4 @@ def get_free_ports(num: Optional[int] = 1) -> int:
ports.append(sock.getsockname()[1])
for sock in socks:
sock.close()
return ports[0] if num == 1 else ports
return ports
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册