I’m developing a small web service with Flask which needs to run background tasks, preferably from a task queue. However, after googling the subject the only results were essentially Celery and Redis Queue, which apparently require separate queuing services and thus are options that are far too heavy and convoluted to deploy. As all I’m looking for is a simple background task queue that enables tasks to be queued and executed on separate threads/processes, does anyone know if there is anything like this available in Python?
3
Answers
The asyncio library might be what you are looking for
After the while statement , you can put the code you want to run in background. Maybe deleting some models , sending email or whatever.
If you are using FastAPI, there is already implementation of BackgroundTasks
You don’t need to implement Threading and Queues for doing background tasks after receiving the request.
Code Implementation: