djangowsgiuwsgi

How to disable threading in a django wsgi application?


I'm deploying a django app that uses signals (so it needs to be run in a single thread). I can disable threading in the development server with

python manage.py runserver --nothreading --noreload

and it works well. To deploy the app I followed the django uwsgi deployment guide and set it up with uwsgi. That is, with

uwsgi ... -module myapp.wsgi

How can I disable the uwsgi threading when running the app like this?

Edit: The web application is an online Mathematica interpreter Mathics, e.g. http://mathics.angusgriffith.com/. The signal are used to implement evaluation time limits. We're currently using threads but because of the GIL evaluation can get 'stuck' since everything is CPU bound. We also tried using multiprocessing but the overhead was too high. Link to the Mathics signals code.


Solution

  • Taking to account your explanation why you need signals in Django application, in my opinion you're doing something terribly wrong.

    If you're just starting computation inside your view, that can take long time, you're freezing whole worker for that time. That means, worker can't process any other request. If you're using 4 workers and there will be 5 users that will submit equation that needs more computation, there won't be resources to process request from one of them, because all 4 workers will be busy computing.

    That means, for larger amount of users you will need lot of workers. Each worker will consume resources and you will run out of them very, very fast.

    In other words, it is very bad practice to run some long tasks inside views.

    Consider using some task queue like celery, send every equation to solve into celery. That way you workers will be available all the time to handle requests and task will be queued. Also it will be lot easier to manage frozen tasks.