0
我在寫一個處理兩個WebSocket的函數,每個WebSocket的響應都會改變一個共享的DataFrame df。如何在Python中以FIFO的方式處理多個WebSockets?
import json
import asyncio
import websockets
@asyncio.coroutine
def printResponse(df, dataSocket, quoteSocket, dataRequest, quoteRequest):
yield from dataSocket.send(dataRequest)
yield from quoteSocket.send(quoteRequest)
response = yield from dataSocket.recv() # skip first response
response = yield from quoteSocket.recv() # skip first response
while True:
response = yield from dataSocket.recv()
print("<< {}".format(json.loads(response)))
df = changeRecord(df, response)
response = yield from quoteSocket.recv()
print("<< {}".format(json.loads(response)))
df = changeRecord(df, response)
我不確定,但目前的代碼似乎輪流處理兩個WebSockets。我想以「先進先出」的方式處理響應,無論它來自哪個WebSocket。我應該如何改變才能達到這個目標?
在這種結構中,做DataSocket技術和quoteSocket工作在相同的DF或兩個獨立的DF? – kinreyli
我的目標是從兩個websockets在同一個df上進行響應。由dataSocket更新的df應該可用於quoteSocket的響應。 – kinreyli
這個結構運作良好。欣賞它! – kinreyli