让函数return之后还能做点后处理的方法.

    async def bounded_task(task: Coroutine) -> Any:
        async with semaphore:
            try:
                return await task
            finally:
                # 无论任务成功/失败,都更新进度条!!!!!!!!!!!!!!!!!!!!!!!这个技巧非常秀,可以让函数retrurn后再干点啥.
                pbar.update()

posted on 2026-01-13 17:09  张博的博客  阅读(0)  评论(0)    收藏  举报

导航