Skip to content

Commit e5b1fb4

Browse files
authored
Pre-load all timezone disk reads on import (#386)
* Pre-load all timezone disk reads on import * Remove dead code
1 parent 272b4a4 commit e5b1fb4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ical/tzif/timezoneinfo.py

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def _read_system_timezones() -> set[str]:
3232
return zoneinfo.available_timezones()
3333

3434

35+
@cache
3536
def _find_tzfile(key: str) -> str | None:
3637
"""Retrieve the path to a TZif file from a key."""
3738
for search_path in zoneinfo.TZPATH:
@@ -63,6 +64,7 @@ def _iana_key_to_resource(key: str) -> tuple[str, str]:
6364
return package, resource
6465

6566

67+
@cache
6668
def read(key: str) -> TimezoneInfo:
6769
"""Read the TZif file from the tzdata package and return timezone records."""
6870
if key not in _read_system_timezones() and key not in _read_tzdata_timezones():
@@ -167,3 +169,11 @@ def read_tzinfo(key: str) -> TzInfo:
167169
return TzInfo.from_timezoneinfo(timezoneinfo)
168170
except ValueError as err:
169171
raise TimezoneInfoError(f"Unable create TzInfo: {key}") from err
172+
173+
174+
# Avoid blocking disk reads in async function by pre-loading all timezone reads
175+
for key in _read_system_timezones():
176+
try:
177+
read_tzinfo(key)
178+
except TimezoneInfoError:
179+
pass

0 commit comments

Comments
 (0)