Фоновая задача в FastAPI не работает должным образомPython

Программы на Python
Гость
Фоновая задача в FastAPI не работает должным образом

Сообщение Гость »


I am performing predictions with FastAPI, using background tasks. Everything seems to be working, but if I warp the background task function in another function and call it then it's not working. Why is this happening? Don't background tasks in FastAPI work when i pass the function this way?
# this is the working example @app.get(api_names[0]) async def predict(background_tasks: BackgroundTasks,solute,solvent): background_tasks.add_task(predictions,solute,solvent) return {'success'} # but when i change the above end point to below its not working @app.get(api_names[0]) async def predict(background_tasks: BackgroundTasks,solute,solvent): sample = predict_dup(0) background_tasks.add_task(sample,solute,solvent) return {'success'} async def predict_dup(task_id): if task_id == 0: return predictions elif task_id == 2: return predictions_two

Источник: https://stackoverflow.com/questions/714 ... g-properly

Вернуться в «Python»