summaryrefslogtreecommitdiff
path: root/leapsecond.py
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-11-27 05:36:49 -0500
committerEric S. Raymond <esr@thyrsus.com>2013-11-27 05:38:26 -0500
commitfb10304635cfb71b6b8186792e973a169bbc80f2 (patch)
treedaa090663632d99e2a974b51dca84665ab1ef49f /leapsecond.py
parent04ce3b99cc51d7febbbfd51c08f2364a4ca71a4d (diff)
downloadgpsd-fb10304635cfb71b6b8186792e973a169bbc80f2.tar.gz
Refactor leap-second cache fetching. No logic changes yet.
Diffstat (limited to 'leapsecond.py')
-rwxr-xr-xleapsecond.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/leapsecond.py b/leapsecond.py
index de24d1a3..87396ddc 100755
--- a/leapsecond.py
+++ b/leapsecond.py
@@ -50,7 +50,7 @@ BSD terms apply: see the file COPYING in the distribution root for details.
"""
-import os, urllib, re, random, time, calendar, math, sys
+import os, urllib, re, random, time, calendar, math, sys, signal
# Set a socket timeout for slow servers
import socket
@@ -253,6 +253,27 @@ def make_leapsecond_include(infile):
#define GPS_WEEK_NOW\t%(gps_week_now)d
""" % locals()
+def conditional_leapsecond_fetch(outfile, timeout):
+ "Fetch leapsecond data, with timeout in case of evil firewalls."
+ def handler(signum, frame):
+ raise IOError
+ try:
+ signal.signal(signal.SIGALRM, handler)
+ except ValueError:
+ # Parallel builds trigger this - signal only works in main thread
+ sys.stdout.write("Signal set failed; ")
+ return False
+ signal.alarm(timeout)
+ sys.stdout.write("Attempting leap-second fetch...")
+ try:
+ save_leapseconds(outfile)
+ sys.stdout.write("succeeded.\n")
+ except IOError:
+ sys.stdout.write("failed; ")
+ return False
+ signal.alarm(0)
+ return True
+
def leastsquares(tuples):
"Generate coefficients for a least-squares fit to the specified data."
sum_x=0