Add connection delay
This commit is contained in:
parent
7f33c60cc6
commit
ea66840d2a
@ -6,6 +6,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from ipaddress import IPv4Address, IPv6Address
|
from ipaddress import IPv4Address, IPv6Address
|
||||||
|
|
||||||
@ -90,17 +91,25 @@ class Engine():
|
|||||||
|
|
||||||
def check_internet(self) -> bool:
|
def check_internet(self) -> bool:
|
||||||
"""Check the internet link just with a small http request
|
"""Check the internet link just with a small http request
|
||||||
to an URL present in the configuration
|
to an URL present in the configuration. If the link is down,
|
||||||
|
retry 3 times.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True if everything works.
|
bool: True if everything works.
|
||||||
"""
|
"""
|
||||||
try:
|
attempts = 3
|
||||||
url = get_config(("network", "internet_check"))
|
|
||||||
requests.get(url, timeout=3)
|
while True:
|
||||||
return True
|
try:
|
||||||
except:
|
url = get_config(("network", "internet_check"))
|
||||||
return False
|
requests.get(url, timeout=3)
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
if attempts == 0:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
time.sleep(5)
|
||||||
|
attempts -= 1
|
||||||
|
|
||||||
def get_public_ip(self) -> list:
|
def get_public_ip(self) -> list:
|
||||||
"""Get the public IP address
|
"""Get the public IP address
|
||||||
|
Loading…
Reference in New Issue
Block a user