Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the database lock error in multithread download #1276

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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