在这种情况下,我需要从协程中获取有关哪个任务失败的信息。
我正在使用asyncio.wait
,并且当任务因异常而失败时,我无法确定是哪个参数导致了任务失败。
我尝试读取coro cr_frame,但是似乎在coro运行之后,cr_frame返回None
我也尝试了其他操作,例如尝试编辑coro类并尝试放置attribute
coro.__mydata = data
,但是我似乎无法在Coro上动态添加属性(也许不知道它对python的限制)
这是一些代码
async def main():
"""
Basically this function send messages to an api
The class takes things like channelID, userID etc
Sometimes channelID, userID are wrong and the task would return an exception
"""
resp = await asyncio.wait(self._queue_send_task)
for r in resp[0]:
try:
sent = r.result()
except:
## Exception because of wrong args, I need the args to act upon them
coro = r.get_coro()
coro.cr_frame ## Returns none, normally this would return a frame if I were to call it before the coro start