【发布时间】:2021-01-12 19:32:55
【问题描述】:
我正在使用 asyncio 通过以下方式等待一组协程:
# let's assume we have fn defined and that it can throw an exception
coros_objects = []
for x in range(10):
coros_objects.append(fn(x))
for c in asyncio.as_completed(coros_objects):
try:
y = await c
exception:
# something
# if possible print(x)
问题是我如何知道哪个协程失败了,以及哪个参数失败了?
我可以将"x" 附加到输出中,但这只会为我提供有关成功执行的信息。
我可以知道表单顺序,因为它与coros_objects 的顺序不同
我能否以某种方式确定 coro 刚刚产生了什么结果?
【问题讨论】: