ntptime: Allow overriding default NTP timeout.

The default 1 second timeout is sometimes not enough depending on the host
and network latencies.  This patch makes timeout configurable.
pull/549/head^2
iabdalkader 2022-10-17 14:32:52 +02:00 zatwierdzone przez Damien George
rodzic 8503017e3b
commit 900dd1c61b
1 zmienionych plików z 3 dodań i 1 usunięć

Wyświetl plik

@ -11,6 +11,8 @@ except:
# The NTP host can be configured at runtime by doing: ntptime.host = 'myhost.org'
host = "pool.ntp.org"
# The NTP socket timeout can be configured at runtime by doing: ntptime.timeout = 2
timeout = 1
def time():
@ -19,7 +21,7 @@ def time():
addr = socket.getaddrinfo(host, 123)[0][-1]
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.settimeout(1)
s.settimeout(timeout)
res = s.sendto(NTP_QUERY, addr)
msg = s.recv(48)
finally: