8000 plot_stock_market example retry on failed download of data from googl… · hakaa1/scikit-learn@91e7990 · GitHub
[go: up one dir, main page]

Skip to content

Commit 91e7990

Browse files
committed
plot_stock_market example retry on failed download of data from google (scikit-learn#9172)
1 parent 5a74e2f commit 91e7990

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

examples/applications/plot_stock_market.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,34 @@
7777
# #############################################################################
7878
# Retrieve the data from Internet
7979

80+
def retry(f, n_retry=3):
81+
"""Define wrapper function to retry function calls in case of Exceptions
8082
83+
Parameters
84+
-----------
85+
f: function
86+
Function that will be wrapped
87+
n_retry: int
88+
Number of retries of function call
89+
90+
Returns
91+
-------
92+
f : function
93+
Wrapped input function
94+
95+
"""
96+
def wrapper(*args, **kwargs):
97+
exception = None
98+
for i in range(n_retry):
99+
try:
100+
return f(*args, **kwargs)
101+
except Exception as e:
102+
exception = e
103+
raise exception
104+
return wrapper
105+
106+
107+
@retry
81108
def quotes_historical_google(symbol, date1, date2):
82109
"""Get the historical data from Google finance.
83110

0 commit comments

Comments
 (0)
0