Skip to content

Commit d32d30b

Browse files
authored
Fix thread safety bug in lazy load pattern (#92)
1 parent d46c84e commit d32d30b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

zxcvbn/matching.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ def get_ranked_dictionaries():
2323
# Do the expensive import here only
2424
from zxcvbn.frequency_lists import FREQUENCY_LISTS
2525

26-
# Build the dictionary once
27-
RANKED_DICTIONARIES = {}
28-
for name, lst in FREQUENCY_LISTS.items():
29-
RANKED_DICTIONARIES[name] = build_ranked_dict(lst)
26+
# Build in local scope before adding to global scope for thread safety
27+
built_dict = {name: build_ranked_dict(lst) for name, lst in FREQUENCY_LISTS.items()}
28+
RANKED_DICTIONARIES = built_dict
3029
return RANKED_DICTIONARIES
3130

3231

0 commit comments

Comments
 (0)