Use sock.settimeout instead of module setdefaulttimeout.

master
voussoir 2021-11-13 01:20:42 -08:00
parent 1bbb8bedee
commit ef546886c9
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 3 additions and 2 deletions

View File

@ -50,11 +50,12 @@ def has_lan():
def has_internet(timeout=2) -> bool:
'''
Return True if an internet connection is available.
Return True if an internet connection is available. Returns False if the
timeout expires.
'''
socket.setdefaulttimeout(timeout)
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout)
sock.connect((INTERNET_IP, 53))
return True
except socket.error as exc: