问题
I'm writing a Django application, which needs to perform long async tasks. Initial idea was to start a subprocess from the view that does that job, and to monitor the progress in another views.
The idea works fine when application is started via manage.py runserver
, but it doesn't when it is run under uwsgi. The child process is started, but after the view returns uwsgi waits for the child process end, which breaks the whole idea.
I can see the request details in the uwsgi log (number of bytes generated, etc), but the socket isn't closed, so the browser waits too.
I have seen other alternatives for running async tasks, e.g. celery, but so far I've spent more time trying to configure celery than I've spent for the task. If there's any other way, I'll be happy to hear how you solved it.
回答1:
http://uwsgi-docs.readthedocs.org/en/latest/ThingsToKnow.html
--close-on-exec is what you need
回答2:
I have found a good alternative: https://github.com/ui/django-rq , which is easy to install and configure, and it does the job correctly.
Original problem with subprocesses is still unclear though.
来源:https://stackoverflow.com/questions/17592692/running-a-subprocess-in-uwsgi-application