stub42 / pytz

pytz Python historical timezone library and database
MIT License
352 stars 93 forks source link

Long running application has started failing with "'_all_timezones_unchecked' is not defined" after recent upgrade #95

Closed gae123 closed 1 year ago

gae123 commented 1 year ago

python version: 2.7.18 pytz version: 2022.7

No changes on my end that could have provoked this.

The exact trace is:

....
File "...", in userTimeZone return pytz.timezone(tz) 
File "pytz/__init__.py", line 179, in timezone zone = _case_insensitive_zone_lookup(_unmunge_zone(zone)) 
File "pytz/__init__.py", line 207, in _case_insensitive_zone_lookup del _all_timezones_unchecked NameError: global name '_all_timezones_unchecked' is not defined

I suspect it has to do with 86568705df89fde7e9271329b0ba06c4a7ad7f1b

stub42 commented 1 year ago

_case_insensitive_zone_lookup is no longer thread safe, and there is a chance of triggering the exception if multiple threads attempt the first timezone lookup at the same time. Reverting the cited commit will fix the issue. Or we can keep the memory (premature) optimization by setting _all_timezones_unchecked to the LazyList all_timezones rather than delete the symbol.