summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Bishop <stuart.bishop@canonical.com>2020-06-01 14:27:30 +1000
committerStuart Bishop <stuart.bishop@canonical.com>2020-06-01 14:27:30 +1000
commit616ca4aaf92cc67beb0df5b883918cbf80e88270 (patch)
tree45e0c7bee8e20cb793e395b163b6dee23576086d
parent1678a0085e723225e00369a8dbf2f77d1385ba2e (diff)
downloadpytz-git-616ca4aaf92cc67beb0df5b883918cbf80e88270.tar.gz
Allow skipping of startup resource checks
If the PYTZ_SKIPEXISTSCHECK environment variable is set, pytz will not confirm the existance of the expected timezone database files at import time. This improves startup time, but will cause crashes when the timezone list baked into the pytz release does not match the timezone database in use. Patch from Timothy Paine
-rw-r--r--src/pytz/__init__.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/pytz/__init__.py b/src/pytz/__init__.py
index c25a1d1..58a678f 100644
--- a/src/pytz/__init__.py
+++ b/src/pytz/__init__.py
@@ -111,6 +111,13 @@ def open_resource(name):
def resource_exists(name):
"""Return true if the given resource exists"""
try:
+ if os.environ.get('PYTZ_SKIPEXISTSCHECK', ''):
+ # In "standard" distributions, we can assume that
+ # all the listed timezones are present. As an
+ # import-speed optimization, you can set the
+ # PYTZ_SKIPEXISTSCHECK flag to skip checking
+ # for the presence of the resource file on disk.
+ return True
open_resource(name).close()
return True
except IOError: