Skip to content

Commit

Permalink
Merge pull request #1276 from gogog22510/main
Browse files Browse the repository at this point in the history
Fix the database lock error in multithread download
  • Loading branch information
ValueRaider committed Jan 4, 2023
2 parents 97adb30 + 2a7588d commit 1495834
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions yfinance/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,10 @@ class _TzCache:
"""Simple sqlite file cache of ticker->timezone"""

def __init__(self):
self._tz_db = None
self._setup_cache_folder()
# Must init db here, where is thread-safe
self._tz_db = _KVStore(_os.path.join(self._db_dir, "tkr-tz.db"))
self._migrate_cache_tkr_tz()

def _setup_cache_folder(self):
if not _os.path.isdir(self._db_dir):
Expand Down Expand Up @@ -776,11 +778,6 @@ def _db_dir(self):

@property
def tz_db(self):
# lazy init
if self._tz_db is None:
self._tz_db = _KVStore(_os.path.join(self._db_dir, "tkr-tz.db"))
self._migrate_cache_tkr_tz()

return self._tz_db

def _migrate_cache_tkr_tz(self):
Expand Down

0 comments on commit 1495834

Please sign in to comment.