【发布时间】:2023-02-16 21:09:38
【问题描述】:
After executing an api in django rest in production mode, the following method is called and executed. After each execution of this method, the amount of RAM usage goes up and up and does not go down, and I don't understand where the problem is.
def download(self):
try:
if self.adjust:
path = Path(UPLOAD_DIR / 'yf_history' / self.market / 'adjusted')
else:
path = Path(UPLOAD_DIR / 'yf_history' / self.market)
path.mkdir(parents=True, exist_ok=True)
data = yfinance.download(
progress=False,
tickers=self.ticker_list,
period=self.period,
interval=self.interval_period,
group_by='ticker',
auto_adjust=self.adjust,
prepost=False,
threads=True,
proxy=None
).T
for ticker in self.ticker_list:
try:
data.loc[(ticker,),].T.dropna().to_csv(path / f'{ticker}{self.suffix}.csv')
except:
pass
del data
except Exception as error:
return False, error
else:
return True, 'Saved successfully'
I don't have this problem with any other function
Python==3.9 Django==3.2.9 djangorestframework==3.13.1 yfinance==0.2.10
Thank you for your advice on the problem and solution.
标签: python django django-rest-framework yfinance