Fix is_online() for faster offline imports (#9544)
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
parent
a2628657a1
commit
fcb0641d7f
1 changed files with 5 additions and 10 deletions
|
|
@ -475,17 +475,12 @@ def is_online() -> bool:
|
|||
Returns:
|
||||
(bool): True if connection is successful, False otherwise.
|
||||
"""
|
||||
import socket
|
||||
with contextlib.suppress(Exception):
|
||||
assert str(os.getenv("YOLO_OFFLINE", "")).lower() != "true" # check if ENV var YOLO_OFFLINE="True"
|
||||
import socket
|
||||
|
||||
for host in "1.1.1.1", "8.8.8.8", "223.5.5.5": # Cloudflare, Google, AliDNS:
|
||||
try:
|
||||
test_connection = socket.create_connection(address=(host, 80), timeout=2)
|
||||
except (socket.timeout, socket.gaierror, OSError):
|
||||
continue
|
||||
else:
|
||||
# If the connection was successful, close it to avoid a ResourceWarning
|
||||
test_connection.close()
|
||||
return True
|
||||
socket.create_connection(address=("1.1.1.1", 80), timeout=1.0).close() # check Cloudflare DNS
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue