mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-12 10:58:21 +08:00
Opt: Faster is_port_using() on startup
From 1s to almost 0ms
This commit is contained in:
@@ -19,9 +19,11 @@ def is_port_using(port_num):
|
|||||||
s.settimeout(2)
|
s.settimeout(2)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = s.connect_ex(('127.0.0.1', port_num))
|
s.bind(('127.0.0.1', port_num))
|
||||||
# if port is using, return code should be 0. (can be connected)
|
return False
|
||||||
return result == 0
|
except OSError:
|
||||||
|
# Address already bind
|
||||||
|
return True
|
||||||
finally:
|
finally:
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user