Use sock.settimeout instead of module setdefaulttimeout.
This commit is contained in:
parent
1bbb8bedee
commit
ef546886c9
1 changed files with 3 additions and 2 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue