import numpy as np
import tushare as ts
import aiohttp
import asyncio
import time
codes = ['787819', '787317', '787317', '600320', '600191', '600191', '600967', '600765', '600238', '603650']
cvs_30 = []
start = time.time()
async def get_index(code):
all_data = ts.get_hist_data(code, start='2020-05-12', end='2020-12-28')
if all_data is None:
cv_30 = 0
# 加入相对应的列表
cvs_30.append(cv_30)
else:
data = all_data['close']
cv_30 = np.std(data.head(30)) / np.mean(data.head(30))
# 加入相对应的列表
cvs_30.append(cv_30 * 1000)
tasks = [asyncio.ensure_future(get_index(code)) for code in codes]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*tasks))
end = time.time()
print(end - start)
python 同步代码改成异步的:各位大佬,下面是我写的读取tushare股票价格的大码,因为有多只股票,写成异步的,但是我写的代码执行后的效果还是同步的效果,请哪位大佬帮我修改下。