Skip to content

Commit

Permalink
Fix disable prints inside threads (bpython deadlock)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValueRaider committed Nov 10, 2022
1 parent ddc3434 commit bad6456
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 9 additions & 6 deletions yfinance/base.py
Expand Up @@ -145,6 +145,9 @@ def history(self, period="1mo", interval="1d",
debug_mode = True
if "debug" in kwargs and isinstance(kwargs["debug"], bool):
debug_mode = kwargs["debug"]
if "many" in kwargs and kwargs["many"]:
# Disable prints with threads, it deadlocks/throws
debug_mode = False

err_msg = "No data found for this date range, symbol may be delisted"

Expand All @@ -155,7 +158,7 @@ def history(self, period="1mo", interval="1d",
# Every valid ticker has a timezone. Missing = problem
shared._DFS[self.ticker] = utils.empty_df()
shared._ERRORS[self.ticker] = err_msg
if "many" not in kwargs and debug_mode:
if debug_mode:
print('- %s: %s' % (self.ticker, err_msg))
return utils.empty_df()

Expand Down Expand Up @@ -215,23 +218,23 @@ def history(self, period="1mo", interval="1d",
if data is None or not type(data) is dict or 'status_code' in data.keys():
shared._DFS[self.ticker] = utils.empty_df()
shared._ERRORS[self.ticker] = err_msg
if "many" not in kwargs and debug_mode:
if debug_mode:
print('- %s: %s' % (self.ticker, err_msg))
return utils.empty_df()

if "chart" in data and data["chart"]["error"]:
err_msg = data["chart"]["error"]["description"]
shared._DFS[self.ticker] = utils.empty_df()
shared._ERRORS[self.ticker] = err_msg
if "many" not in kwargs and debug_mode:
if debug_mode:
print('- %s: %s' % (self.ticker, err_msg))
return shared._DFS[self.ticker]

elif "chart" not in data or data["chart"]["result"] is None or \
not data["chart"]["result"]:
shared._DFS[self.ticker] = utils.empty_df()
shared._ERRORS[self.ticker] = err_msg
if "many" not in kwargs and debug_mode:
if debug_mode:
print('- %s: %s' % (self.ticker, err_msg))
return shared._DFS[self.ticker]

Expand All @@ -246,7 +249,7 @@ def history(self, period="1mo", interval="1d",
except Exception:
shared._DFS[self.ticker] = utils.empty_df()
shared._ERRORS[self.ticker] = err_msg
if "many" not in kwargs and debug_mode:
if debug_mode:
print('- %s: %s' % (self.ticker, err_msg))
return shared._DFS[self.ticker]

Expand Down Expand Up @@ -282,7 +285,7 @@ def history(self, period="1mo", interval="1d",
err_msg = "back_adjust failed with %s" % e
shared._DFS[self.ticker] = utils.empty_df()
shared._ERRORS[self.ticker] = err_msg
if "many" not in kwargs and debug_mode:
if debug_mode:
print('- %s: %s' % (self.ticker, err_msg))

if rounding:
Expand Down
8 changes: 4 additions & 4 deletions yfinance/multi.py
Expand Up @@ -198,7 +198,7 @@ def _download_one_threaded(ticker, start=None, end=None,

data = _download_one(ticker, start, end, auto_adjust, back_adjust,
actions, period, interval, prepost, proxy, rounding,
keepna, timeout)
keepna, timeout, many=True)
shared._DFS[ticker.upper()] = data
if progress:
shared._PROGRESS_BAR.animate()
Expand All @@ -208,11 +208,11 @@ def _download_one(ticker, start=None, end=None,
auto_adjust=False, back_adjust=False,
actions=False, period="max", interval="1d",
prepost=False, proxy=None, rounding=False,
keepna=False, timeout=None):
keepna=False, timeout=None, many=False):

return Ticker(ticker).history(period=period, interval=interval,
start=start, end=end, prepost=prepost,
actions=actions, auto_adjust=auto_adjust,
back_adjust=back_adjust, proxy=proxy,
rounding=rounding, keepna=keepna, many=True,
timeout=timeout)
rounding=rounding, keepna=keepna, timeout=timeout,
many=many)

0 comments on commit bad6456

Please sign in to comment.