File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
lmdeploy/pytorch/engine/executor Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 66import torch .distributed as dist
77
88
9- def find_available_port () -> bool :
9+ def find_available_port (start_port : int = 0 ) -> int :
1010 """find available port."""
11- port = 29500
12- while True :
13- with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
14- if s .connect_ex (('localhost' , port )) != 0 :
15- return port
16- port += 1
11+ with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
12+ try :
13+ s .bind (('127.0.0.1' , start_port ))
14+ port = s .getsockname ()[1 ]
15+ return port
16+ except socket .error as e :
17+ if start_port == 0 :
18+ raise RuntimeError ('Failed to find available port.' ) from e
19+ return find_available_port (0 )
1720
1821
1922def setup_master_addr (addr : str , port : str ):
You can’t perform that action at this time.
0 commit comments