How to parallelize the for loop inside a async function and track for loop execution status?
- 阅读更多 关于 How to parallelize the for loop inside a async function and track for loop execution status?
问题 Recently, I have asked a question regarding how to track the progress of a for loop inside a API deployed. Here's the link. The solution code that worked for me is, from fastapi import FastAPI, UploadFile from typing import List import asyncio import uuid context = {'jobs': {}} app = FastAPI() async def do_work(job_key, files=None): iter_over = files if files else range(100) for file, file_number in enumerate(iter_over): jobs = context['jobs'] job_info = jobs[job_key] job_info['iteration'] =