Asyncio:发生异常时等待完成的任务

Asyncio : Waiting for completed task when an exception occurs

该代码有 5 个工作人员在工作。 每个工人都是这样(简码):

async def worker(name):   

   queue_item = await queue.get()
   msg = queue_item.message  #<--- first attempt
   #.....#

    try:
        #...get_message fails(timeout)...raise#

    except errors.TimedOutError:
        #Retry to get the message
        msg = await get_messages(queue_item.channel, ids=queue_item.id)  # <-- retry                      

        #in order to process it again I put it in different queue 
        await queue_retry.put(msg)  

但是, await queue_retry 是否在更新队列之前等待 msg = await get_messages 完成?

如果没有,我不知道它会放入什么信息,我怀疑它不会等待新的 get_message 而会放入旧的。

Does the await queue_retry wait for msg = await get_messages to complete before to update the queue?

是:await get_messages(...) 会等待 get_messages(...) 完成后再继续。如果您不确定,请将变量名称更改为 emg msg2(在 awaitqueue_retry.put lines 中)以说服自己您不是在处理旧的 msg .