Couple of corrections after looking at this again:
ntpq_stat = subprocess.check_output(["/usr/local/bin/ntpq", "-pn"],
shell=False, stderr=subprocess.STDOUT)
while is_ntp_up() == 0:
Chris
On Sunday, April 21, 2019 at 6:22:06 PM UTC-7, [email protected] wrote:
>
> Here's an alternative that I'm putting into extensions.py. Seems to do
> the trick, but could be a little more elegant...
> python's re lib isn't as helpful as perl's about capturing values.
>
> import re
> import time
> import subprocess
>
> def is_ntp_up():
> ntpq_stat = sybprocess.call_check(["/usr/local/bin/ntpq", "-pn"],
> buffsize=1024, shell=False, stderr=subprocess.STDOUT)
> for line in ntpq_stat.split('\n'):
> if re.match("\*\d+\..*\s+\S+\s+\d+", line):
> fields = line.split()
> if int(fields[2]) > -1 and int(fields[2]) < 16:
> return 1
> return 0
>
> wait_loop_limit = 60 # wait up to 5 minutes for ntp to sync
> wait_loops = 0
> while is_ntp_up == 0:
> time.sleep(5)
> print "Waiting for NTP to come up"
> wait_loops += 1
> if wait_loops > wait_loop_limit:
> raise Exception(" No ntp sync, exiting now")
>
> Chris
>
>
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.