提问人:Albert Gregor 提问时间:10/21/2023 最后编辑:Albert Gregor 更新时间:10/22/2023 访问量:38
如何在 AsyncIO 函数中使用多个 await
How to use multiple await in AsyncIO function
问:
self.ws = await self.client.ws_connect()#Aiohttp client session
self.rx_task = asyncio.get_event_loop().create_task(self._rx_task())
self.file_writer = await aiofiles.open('server_log.txt', 'wb')
self.rx_queue = asyncio.Queue()
async def _rx_task(self):
"""
Async function to collect the task and put into queue.
"""
try:
while True:
msg = await self.ws.receive_json()
#print(msg)
await self.file_writer.write(msg)
self.rx_queue.put_nowait(msg)
except asyncio.CancelledError:
pass
我卡在file_writer.write()上。我想在将 ws 收到的 msg 写入文件之前将其写入队列
答: 暂无答案
评论
async_open
self.xxxx = ....
__init__