The cache may be cleared between the evaluation of the if statement and the
call to popitem.
cls._strong_cache[key] = cls._strong_cache.pop(key, instance)
if len(cls._strong_cache) > cls._strong_cache_size:
- cls._strong_cache.popitem(last=False)
+ try:
+ cls._strong_cache.popitem(last=False)
+ except KeyError:
+ # another thread may have already emptied the cache
+ pass
return instance
--- /dev/null
+Fix a race condition between :class:`zoneinfo.ZoneInfo` creation and
+:func:`zoneinfo.ZoneInfo.clear_cache` that could raise :exc:`KeyError`.