Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ColossalAI
Commits
a8480911
Unverified
Commit
a8480911
authored
Feb 28, 2023
by
YH
Committed by
GitHub
Feb 28, 2023
Browse files
Fix port exception type (#2925)
parent
61e68783
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
8 deletions
+12
-8
colossalai/utils/common.py
colossalai/utils/common.py
+12
-8
No files found.
colossalai/utils/common.py
View file @
a8480911
...
...
@@ -50,16 +50,20 @@ def ensure_path_exists(filename: str):
Path
(
dirpath
).
mkdir
(
parents
=
True
,
exist_ok
=
True
)
def
free_port
():
def
free_port
()
->
int
:
"""Get a free port on localhost.
Returns:
int: A free port on localhost.
"""
while
True
:
port
=
random
.
randint
(
20000
,
65000
)
try
:
sock
=
socket
.
socket
()
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
port
=
random
.
randint
(
20000
,
65000
)
sock
.
bind
((
'localhost'
,
port
))
sock
.
close
()
return
port
except
Exception
:
with
socket
.
socket
()
as
sock
:
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
sock
.
bind
((
"localhost"
,
port
))
return
port
except
OSError
:
continue
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment