From ef546886c9b85d4dbe3cc74fac076096a4e8b7b9 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 13 Nov 2021 01:20:42 -0800 Subject: [PATCH] Use sock.settimeout instead of module setdefaulttimeout. --- voussoirkit/networktools.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/voussoirkit/networktools.py b/voussoirkit/networktools.py index 82924bd..e6ae472 100644 --- a/voussoirkit/networktools.py +++ b/voussoirkit/networktools.py @@ -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: