-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uniform code style for utils for better readability (#108)
- Loading branch information
1 parent
2d3cd33
commit ba40f3b
Showing
2 changed files
with
13 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import socket | ||
|
||
|
||
|
||
def alloc_can_use_network_port(num=3, used_nccl_port=None): | ||
port_list = [] | ||
for port in range(10000, 65536): | ||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
result = s.connect_ex(('localhost', port)) | ||
result = s.connect_ex(("localhost", port)) | ||
if result != 0 and port != used_nccl_port: | ||
port_list.append(port) | ||
|
||
if len(port_list) == num: | ||
return port_list | ||
return None | ||
return None |