Use sock.settimeout instead of module setdefaulttimeout.

This commit is contained in:
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

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: