A simple approach to running a background task in Django

I have a Django site, and on one page there is a button (or link) that, when clicked, launches a somewhat long task. Obviously, I want to run this task as a background task and immediately return the result to the user. I want to implement this using a simple approach that won't require me to install and learn a whole new messaging architecture like Celery. I do not want to use celery! I just want to use a simple approach that I can set up and run in the next half hour or so. Isn't there an easy way to do this in Django without adding (another) third-party package?

+8
python asynchronous django deferred background-process
source share
3 answers

Take a look at django-background-tasks - it does exactly what you need and does not require any additional services to work, such as RabbitMQ or Redis. It manages the task queue in the database and has a Django management command that you can run once or as a cron job.

+5
source share

Just use the stream.

import threading t = threading.Thread(target=long_process, args=args, kwargs=kwargs) t.setDaemon(True) t.start() return HttpResponse() 

See this question for more information: Can Django do multithreaded work?

+4
source share

If you want to install a third-party library, but you need something a lot easier than Celery, check out Redis Queue. This requires Redis, which is pretty easy on its own, but it can also provide many other benefits.

RQ itself has an almost zero configuration. It is amazingly simple.

Literature:

+1
source share

All Articles