Skip to content

Commit 4e3429c

Browse files
committed
net/ntptime/ntptime.py: Make the default timeout configurable.
* The default 1 second timeout is sometimes not enough depending on the host and network latencies. This patch makes timeout configurable.
1 parent 0c5880d commit 4e3429c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

micropython/net/ntptime/ntptime.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
except:
1010
import struct
1111

12+
1213
# The NTP host can be configured at runtime by doing: ntptime.host = 'myhost.org'
1314
host = "pool.ntp.org"
15+
# The NTP socket timeout can be configured at runtime by doing: ntptime.timeout = 1.0
16+
timeout = 1.0
1417

1518

1619
def time():
@@ -19,7 +22,7 @@ def time():
1922
addr = socket.getaddrinfo(host, 123)[0][-1]
2023
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
2124
try:
22-
s.settimeout(1)
25+
s.settimeout(timeout)
2326
res = s.sendto(NTP_QUERY, addr)
2427
msg = s.recv(48)
2528
finally:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy