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 disable prints inside threads (bpython deadlock) #1163

Merged
merged 1 commit into from Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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