Я хочу вернуть переменную из asyncio.ensure_future, но не могу найти правильное решение.
Это мой код:
connectionData = [...]
async def websocketConnect():
data_dic = []
def startReceiving(arg):
r = requests.get(".../realTimeServer/start", params = wsParams)
r = requests.get(".../realTimeServer/negotiate", params = {...})
response = r.json()
wsParams = {...}
websocketUri = f".../realTimeServer/connect?{urllib.parse.urlencode(wsParams)}"
result = []
async with websockets.connect(websocketUri) as websocket:
thread = Thread(target = startReceiving, args = (0, ))
thread.start()
for i in range(0,10):
data = await websocket.recv()
jsonData = json.loads(data)
result= jsonData["M"][0]["A"][0]
break
thread.join()
global data_dic
data_dic.append([datetime.datetime.now(), json.dumps(result, indent=4, sort_keys=True)])
return data_dic
def scrap_data():
#change this to return data_dic
asyncio.ensure_future(websocketConnect())
return data_dic