@@ -52,23 +52,24 @@ def log(evt, **kwargs):
52
52
kwargs ['timestamp' ] = time .strftime ("%Y-%m-%d %H:%M:%S %z" )
53
53
return sys .stderr .write (str (kwargs ) + "\n " )
54
54
55
- # Check that this client's version matches the most recent available, runs just once per program execution (on initial module load).
55
+ # Check that this client's version matches the most recent available. This
56
+ # is intended to run just once per program execution, on initial module load.
57
+ # See the bottom of this file for the ultimate call to this method.
56
58
@staticmethod
57
59
def _version_check ():
58
60
try :
59
- latest_version = requests .get ('https://pypi.org/pypi/delphi-epidata/json' ).json ()['info' ]['version' ]
60
- if latest_version != __version__ :
61
- Epidata .log (
62
- "Client version not up to date" ,
63
- client_version = __version__ ,
64
- latest_version = latest_version
65
- )
61
+ request = requests .get ('https://pypi.org/pypi/delphi-epidata/json' , timeout = 5 )
62
+ latest_version = request .json ()['info' ]['version' ]
66
63
except Exception as e :
67
64
Epidata .log ("Error getting latest client version" , exception = str (e ))
65
+ return
68
66
69
- # Run this once on module load. Use dunder method for Python <= 3.9 compatibility
70
- # https://stackoverflow.com/a/12718272
71
- _version_check .__func__ ()
67
+ if latest_version != __version__ :
68
+ Epidata .log (
69
+ "Client version not up to date" ,
70
+ client_version = __version__ ,
71
+ latest_version = latest_version
72
+ )
72
73
73
74
# Helper function to cast values and/or ranges to strings
74
75
@staticmethod
@@ -708,3 +709,10 @@ async def async_make_calls(param_combos):
708
709
future = asyncio .ensure_future (async_make_calls (param_list ))
709
710
responses = loop .run_until_complete (future )
710
711
return responses
712
+
713
+
714
+
715
+ # This should only run once per program execution, on initial module load,
716
+ # as a result of how Python's module system works:
717
+ # https://docs.python.org/3/reference/import.html#the-module-cache
718
+ Epidata ._version_check ()
0 commit comments