Skip to content

Commit 616ca4a

Browse files
author
Stuart Bishop
committed
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
1 parent 1678a00 commit 616ca4a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/pytz/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ def open_resource(name):
111111
def resource_exists(name):
112112
"""Return true if the given resource exists"""
113113
try:
114+
if os.environ.get('PYTZ_SKIPEXISTSCHECK', ''):
115+
# In "standard" distributions, we can assume that
116+
# all the listed timezones are present. As an
117+
# import-speed optimization, you can set the
118+
# PYTZ_SKIPEXISTSCHECK flag to skip checking
119+
# for the presence of the resource file on disk.
120+
return True
114121
open_resource(name).close()
115122
return True
116123
except IOError:

0 commit comments

Comments
 (0)