From 226620d269d9a5dcb9639e1430c240f4764f87ac Mon Sep 17 00:00:00 2001 From: connorsanders Date: Tue, 12 Dec 2023 23:01:19 -0600 Subject: [PATCH] Refactored session management system to handle cookie and crumbs better. Added fixes for #167, #166, #160. --- yahoofinancials/cache.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/yahoofinancials/cache.py b/yahoofinancials/cache.py index fb9ed94..135a5ea 100644 --- a/yahoofinancials/cache.py +++ b/yahoofinancials/cache.py @@ -1,4 +1,6 @@ import logging +import time + import peewee as _peewee from threading import Lock import os as _os @@ -345,10 +347,18 @@ def initialise(self): if db is None: self.initialised = 0 # failure return - db.connect() - Cookie_db_proxy.initialize(db) - db.create_tables([_CookieSchema]) - self.initialised = 1 # success + i = 0 + while i < 100: + try: + db.connect() + Cookie_db_proxy.initialize(db) + db.create_tables([_CookieSchema]) + self.initialised = 1 # success + return + except _peewee.OperationalError: + time.sleep(10) + continue + def lookup(self, strategy): if self.dummy: